Created
December 31, 2014 06:30
-
-
Save yuizumi/ce6809a5685fb056df13 to your computer and use it in GitHub Desktop.
20141231 and 20150101 are consecutive primes?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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