mituri

[C++] 10001-sza liczba pierwsza

Oct 1st, 2015
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. /*
  2. Project Euler("https://projecteuler.net/archives")
  3. Problem 7
  4.  
  5. By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.
  6. What is the 10 001st prime number?
  7. */
  8.  
  9. int main(){
  10.  
  11. long long num = 1000000, exist = 0;
  12. bool primeFactor = true;
  13.  
  14. for (long long i = 2; i < num; i++){
  15. for(long long j = 1; j < i; j++){
  16. if( j != 1 && i%j == 0) primeFactor = false;
  17. }
  18. if(primeFactor == true){
  19. exist++;
  20. if(exist == 10001) cout << i << endl;
  21. }
  22. primeFactor = true;
  23. }
  24. system("PAUSE");
  25. }
Advertisement
Add Comment
Please, Sign In to add comment