MyCave

Problem 7

Sum square difference

By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.

What is the 10 001st prime number?

function nextPrime(number, cnt) {
    number++;
    while(number > 0 ) {
        if( isPrime(number, cnt) ){
            return number;
        }
        number++;
    }
}

function isPrime( number, cnt){
    var max = Math.sqrt(number, cnt);
    for(var cnt = 2; cnt <= max; cnt++){
        if( number % cnt === 0){
            return false;
        }
    }
    return true;
}

var num = 1;
for(var cnt = 1; cnt <= 10001; cnt++){
    num = nextPrime(num, cnt);
}
console.log('result->', num);