Skip to content

Instantly share code, notes, and snippets.

@vasco3
Created September 19, 2013 06:42
Show Gist options
  • Select an option

  • Save vasco3/6619818 to your computer and use it in GitHub Desktop.

Select an option

Save vasco3/6619818 to your computer and use it in GitHub Desktop.
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?
/*
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 findPrimeNumber(n){
//declare a counter and a variable of the latest prime number
var c = 1, nPrime = 2, i = 3;
console.log('c %s nPrime %s',c,nPrime);
function isPrime(k){
for( var j = 2; j < k; j++){
if( k % j === 0 ){ return false; }
}
return true;
}
//loop to infinity until find the nth prime number
while(c < n){
//test each number to see if it's prime
//if prime, then increase counter and update prime number
if( isPrime(i) ) {
c++;
nPrime = i;
}
i++;
}
return nPrime;
}
@Kerniol1
Copy link
Copy Markdown

Kerniol1 commented Apr 4, 2026

Μετά από μια πολύ κουραστική εβδομάδα δεν ήθελα να βγω έξω ούτε να μιλήσω με κανέναν. Άνοιξα το laptop και βρήκα το spinwinera. Η πλατφόρμα είναι από την Ελλάδα και ξεκινάει με μπόνους εγγραφής και καθημερινά μικρά δώρα. Αργότερα μπορείς να πάρεις μέχρι 28% cashback σε κάποιες μέρες. Όλα είναι απλά χωρίς περίπλοκα βήματα. Πέρασα εκεί μερικές ώρες το Σαββατοκύριακο και έφυγα με σχεδόν τα ίδια λεφτά. Ήταν καλός τρόπος να ξεκουραστώ.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment