Advertisement
warmi12

Liczby pierwsze

Sep 23rd, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.45 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. bool czy_pierwsza(int n)
  7. {
  8.    
  9.     if (n<2) return false;
  10.  
  11.     for(int i=2;i<=sqrt(n);i++)
  12.         if(n%i==0)
  13.             return false; //gdy znajdziemy dzielnik, to dana liczba nie jest pierwsza
  14.     return true;
  15. }
  16.  
  17.  
  18. int main()
  19. {
  20.     int test,n;
  21.    
  22.     cin>>test;
  23.    
  24.     for(int i=0; i<test; i++)
  25.     {
  26.         cin>>n;
  27.         if(czy_pierwsza(n))
  28.         {
  29.             cout<<"TAK"<<endl;
  30.         }
  31.         else cout<<"NIE"<<endl;
  32.        
  33.     }
  34.    
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement