fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. /* Name of the class has to be "Main" only if the class is public. */
  6. class Ideone
  7. {
  8. // 100万までの素数素数を求める
  9. public static void main (String[] args) throws java.lang.Exception {
  10. long t = System.currentTimeMillis();
  11.  
  12. boolean[] p = new boolean[1000000];
  13. for(int i = 3; i < 1000; i += 2){
  14. for(int j = i*i; j < 1000000; j += i+i) p[j] = true;
  15. }
  16.  
  17. int[] prime = new int[80000];
  18. prime[0] = 2;
  19. int n = 0;
  20. for(int i = 3; i < 1000000; i += 2){
  21. if(!p[i]) prime[++n] = i;
  22. }
  23.  
  24. t = System.currentTimeMillis() - t;
  25. System.out.println(t + "ms");
  26. System.out.println(n);
  27. }
  28. }
Success #stdin #stdout 0.05s 4386816KB
stdin
Standard input is empty
stdout
10ms
78497