OneDrain

Untitled

Sep 10th, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.96 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. bool prim(int n)
  6. {
  7.     if(n < 2) // VERIFIC DACA E MAI MIC DECAT 2
  8.         return 0; //NU E PRIM
  9.     else
  10.         for(int d = 2; d * d <= n; d++) //NUMAR DE DIVIZORI EXCLUZANDU-L PE n
  11.             if(n % d == 0) // VERIFICAM DACA NUMARUL SE IMPARTE EXACT LA NUMARUL DE DIVIZORI
  12.                 return 0; // DACA DA, NU E PRIM.
  13.     return 1; // DACA PROGRAMUL AJUNGE PANA LA LINIA ASTA DE COD, INSEAMNA CA NUMARUL DAT ESTE PRIM.
  14. }
  15.  
  16. int n, x, v[101];
  17.  
  18. int main()
  19. {
  20.     cin >> n;
  21.     if(prim(n)) //DACA n E PRIM.
  22.         cout << "EVRIKA! ESTE PRIM!!!";
  23.     else //DACA NU E PRIM.
  24.         cout << "Cacat.. Nu este prim...";
  25.  
  26.     cin >> x;
  27.     for(int i = 1; i <= x; i++)
  28.         cin >> v[i];
  29.     for(int i = 1; i <= x; i++)
  30.     {
  31.         if(prim(v[i]))
  32.             cout << "EVRIKA! ESTE PRIM!!!" << endl;
  33.         else //DACA NU E PRIM.
  34.             cout << "Cacat.. Nu este prim..." << endl;
  35.     }
  36.     return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment