Skip to content

Instantly share code, notes, and snippets.

@yuizumi
Created December 31, 2014 06:30
Show Gist options
  • Save yuizumi/ce6809a5685fb056df13 to your computer and use it in GitHub Desktop.
Save yuizumi/ce6809a5685fb056df13 to your computer and use it in GitHub Desktop.
20141231 and 20150101 are consecutive primes?
// A program to see if 20141231 and 20150101 are consecutive prime numbers.
// Answer: Nope, neither is a prime, and there are lots of primes in between!
class Main
{
private static int minFactor(int n)
{
assert (n >= 3) && (n % 2 != 0);
for (int j = 3; j * j <= n; j += 2) {
if (n % j == 0) {
return j;
}
}
return n;
}
public static void main(String[] args)
{
for (int k = 20141231; k <= 20150101; k += 2) {
System.out.printf("%d: %d%n", k, minFactor(k));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment