Created
November 23, 2013 13:38
-
-
Save reminchev/7614677 to your computer and use it in GitHub Desktop.
What is 1001 Prime number
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cmath> | |
using namespace std; | |
int a[1001]; | |
//Отделна ф-ия дали числото е просто | |
//работи само при последователно смятане на прости числа | |
// и работи като: дали проверяваното число се дели на простите числа преди неговия корен квадратен. | |
bool isPrime(int number) | |
{ | |
int j = 1; | |
while (a[j] <= sqrt(number)) | |
{ | |
if ( number % a[j] == 0) | |
return false; | |
j++; | |
} | |
return true; | |
} | |
int main () | |
{ | |
//Започваме масива от 1 за да ни е по-лесно да се ориентираме | |
//и вкарваме в него първите няколко просто числа | |
a[1] = 2; | |
a[2] = 3; | |
a[3] = 5; | |
int n = 4; | |
int i = 6; | |
while ( n <= 1001 ) | |
{ | |
if (isPrime(i)) | |
{ | |
a[n] = i; | |
cout << "a[" << n << "] = " << a[n]<<endl; // Изкарваме си всички прости числа с това | |
n++; | |
} | |
i++; | |
} | |
cout << "Chisloto e: " <<a[1001]<< endl; // Това е 1001-то просто число | |
system("pause"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment