Created
August 19, 2016 20:33
-
-
Save maksverver/fbb6c0417f8c8bfc112345ecf9f6448b to your computer and use it in GitHub Desktop.
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
class A { | |
public static boolean isPrime(int i) { | |
if (i < 2) return false; | |
for (int j = 2; j <= (int) Math.sqrt(i); ++j) { | |
if (i % j == 0) return false; | |
} | |
return true; | |
} | |
public static void main(String... args) { | |
int count = 0; | |
for (int i = 0; i < 10_000_000; ++i) { | |
if (isPrime(i)) ++count; | |
} | |
System.out.println(count); | |
} | |
} |
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
class B { | |
public static boolean isPrime(int i) { | |
if (i < 2) return false; | |
final int limit = (int)Math.sqrt(i); | |
for (int j = 2; j <= limit; ++j) { | |
if (i % j == 0) return false; | |
} | |
return true; | |
} | |
public static void main(String... args) { | |
int count = 0; | |
for (int i = 0; i < 10_000_000; ++i) { | |
if (isPrime(i)) ++count; | |
} | |
System.out.println(count); | |
} | |
} |
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
class C { | |
public static boolean isPrime(int i) { | |
if (i < 2) return false; | |
for (int j = 2; j*j <= i; ++j) { | |
if (i % j == 0) return false; | |
} | |
return true; | |
} | |
public static void main(String... args) { | |
int count = 0; | |
for (int i = 0; i < 10_000_000; ++i) { | |
if (isPrime(i)) ++count; | |
} | |
System.out.println(count); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment