Advertisement
karbaev

primes-eratosphen-noarr

Feb 29th, 2016
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.52 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. typedef unsigned int uInt;
  4. using namespace std;
  5. int main()
  6. {
  7.     bool is_prime;
  8.  
  9.     uInt count = 1;
  10.     uInt my_prime = 2; //первое простое
  11.  
  12.     for(uInt i = 3; count < 10001; i += 2) { //пропускаем все четные, находим 10001е простое
  13.  
  14.         is_prime = true;
  15.  
  16.         for(uInt j = 3; j * j <= i && is_prime; j += 2) //пропускаем четные
  17.             if(i % j == 0) is_prime = false;
  18.  
  19.         if(is_prime) {
  20.             ++count;
  21.             my_prime = i;
  22.         }
  23.     }
  24.  
  25.     cout << my_prime;
  26.  
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement