Advertisement
MeehoweCK

Untitled

Aug 16th, 2022
650
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.53 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. bool czy_pierwsza(unsigned long long liczba)
  6. {
  7.     if(liczba < 2)
  8.         return false;
  9.     for(unsigned i = 2; i * i <= liczba; ++i)
  10.         if(liczba % i == 0)
  11.             return false;
  12.     return true;
  13. }
  14.  
  15. int main()
  16. {
  17.     unsigned long long liczba;
  18.     cout << "Podaj liczbe naturalna: ";
  19.     cin >> liczba;
  20.  
  21.     if(czy_pierwsza(liczba))
  22.         cout << liczba << " jest liczba pierwsza.\n";
  23.     else
  24.         cout << liczba << " nie jest liczba pierwsza.\n";
  25.  
  26.     return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement