SingleCorePrimeTest.java 627 B

123456789101112131415161718192021222324252627
  1. /* @author Axel Busch */
  2. public class SingleCorePrimeTest {
  3. public static boolean isPrime(int n) {
  4. if (n < 2) {
  5. return false;
  6. }
  7. for (int i = 2; i <= Math.sqrt(n); ++i) {
  8. if (n % i == 0) {
  9. return false;
  10. }
  11. }
  12. return true;
  13. }
  14. public static void main(String[] args) {
  15. int target = 10_000_000;
  16. long start = System.currentTimeMillis();
  17. for (int i = 2; i <= target; ++i) {
  18. isPrime(i);
  19. }
  20. long end = System.currentTimeMillis();
  21. System.out.println(end-start);
  22. }
  23. }