fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Solution {
  9. public static void main(String[] args) {
  10. int MAX = 1000000;
  11. int T = 0;
  12. boolean isPrime[] = new boolean[MAX];
  13. for(int i=2; i<isPrime.length; i++)
  14. isPrime[i] = true;
  15.  
  16. int primes[] = new int[MAX];
  17. int p = 0;
  18. for(int i=2;i<MAX;i++){
  19. if(isPrime[i]){
  20. primes[p++] = i;
  21. for(int j=2*i; j<MAX; j+=i)
  22. isPrime[j] = false;
  23. }
  24. }
  25. System.out.println("All your prime numbers are calculated, just for example I am taking out the 10101th prime number");
  26. T = 10101;
  27. System.out.println(primes[T]);
  28. }
  29. }
Success #stdin #stdout 0.13s 320576KB
stdin
Standard input is empty
stdout
All your prime numbers are calculated, just for example I am taking out the 10101th prime number
105967