Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- bool prim(int n)
- {
- if(n < 2) // VERIFIC DACA E MAI MIC DECAT 2
- return 0; //NU E PRIM
- else
- for(int d = 2; d * d <= n; d++) //NUMAR DE DIVIZORI EXCLUZANDU-L PE n
- if(n % d == 0) // VERIFICAM DACA NUMARUL SE IMPARTE EXACT LA NUMARUL DE DIVIZORI
- return 0; // DACA DA, NU E PRIM.
- return 1; // DACA PROGRAMUL AJUNGE PANA LA LINIA ASTA DE COD, INSEAMNA CA NUMARUL DAT ESTE PRIM.
- }
- int n, x, v[101];
- int main()
- {
- cin >> n;
- if(prim(n)) //DACA n E PRIM.
- cout << "EVRIKA! ESTE PRIM!!!";
- else //DACA NU E PRIM.
- cout << "Cacat.. Nu este prim...";
- cin >> x;
- for(int i = 1; i <= x; i++)
- cin >> v[i];
- for(int i = 1; i <= x; i++)
- {
- if(prim(v[i]))
- cout << "EVRIKA! ESTE PRIM!!!" << endl;
- else //DACA NU E PRIM.
- cout << "Cacat.. Nu este prim..." << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment