Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- bool czy_pierwsza(unsigned x)
- {
- if(x == 1 || x == 0)
- return false;
- if(x == 2)
- return true;
- for(unsigned i = 2; i <= pow(x,0.5); ++i)
- {
- if(x % i == 0)
- return false;
- }
- return true;
- }
- unsigned nastepna_pierwsza(unsigned n)
- {
- for(unsigned i = n + 1; true; ++i)
- if(czy_pierwsza(i))
- return i;
- }
- int main()
- {
- unsigned n;
- cout << "Podaj liczbe naturalna: ";
- cin >> n;
- if(czy_pierwsza(n))
- cout << "Podana liczba jest liczba pierwsza" << endl;
- else
- {
- cout << "Podana liczba nie jest liczba pierwsza. Najmniejsza liczba pierwsza wieksza od " << n << " jest liczba ";
- cout << nastepna_pierwsza(n) << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement