Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int n, f[1000], e[1000];
- void Descompunere(int n)
- {
- int i = 0, fact, exp = 0;
- for(fact = 2; n != 1; fact++)
- {
- while(n % fact == 0)
- {
- exp++;
- n /= fact;
- }
- if(exp != 0)
- {
- f[i] = fact;
- e[i] = exp;
- i++;
- }
- exp = 0;
- }
- }
- int Prim(int n)
- {
- /*for(int i = 2; i*i <= n; i++)
- if(n % i == 0)
- return 0;
- return 1;*/
- if(n < 2)
- return 0;
- Descompunere(n);
- if((e[0] == 1) && (f[1] == 0))
- return 1;
- return 0;
- }
- int Divizori(int n)
- {
- Descompunere(n);
- int div = 1;
- for(int i = 0; e[i] != 0; i++)
- div *= e[i]+1;
- return div;
- }
- void Afisare(int a[], int n)
- {
- for(int i = 0; i < n; i++)
- cout << a[i] << " ";
- cout << "\n\n";
- }
- int main()
- {
- cin >> n;
- Descompunere(n);
- Afisare(f, 10);
- Afisare(e, 10);
- if(Prim(n) == 1) cout << n << " este numar prim.\n";
- else cout << n << " nu este numar prim.\n";
- cout << n << " are " << Divizori(n) << " divizori.";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement