Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main() {
- const int max = 1000000;
- int count = 1;
- bool arr[max];
- for(int i = 0; i < max; ++i)
- arr[i] = true;
- for(int i = 2; i < max-1; ) {
- if(count == 10001){ //вывод 10001 простого числа
- cout<<i<<endl;
- break;
- }
- //помечаем все кратные
- for(int j = 2; (j*i) < max-1; ++j){
- arr[i*j] = false;
- }
- //находим следующее простое
- for(int k = i+1; k < max-1; k++){
- if(arr[k]) {
- i=k;
- ++count;
- break;
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement