Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package millPrime;
- public class MillionthPrime {
- public static void main(String[] args) {
- final long startTime = System.currentTimeMillis();
- int pFactorCount = 0;
- int checkFactor;
- for(int toFactor = 1; toFactor > 0; toFactor = toFactor + 2){
- int numFactors = 0;
- for (int i=1; i*i <= toFactor; i+=2){
- if(i%3 == 0){
- continue;
- }
- checkFactor = toFactor % i;
- if (checkFactor == 0){
- numFactors++;
- if (numFactors > 1){
- break;
- }
- }
- }
- if (numFactors== 1){
- pFactorCount++;
- System.out.println(pFactorCount);
- if (pFactorCount == 1000000000){
- System.out.println("The millionth prime is "+ toFactor);
- final long endTime = System.currentTimeMillis();
- System.out.println("Time: "+ (endTime - startTime));
- System.exit(0);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement