Advertisement
J00ker

(9-30)T

Sep 29th, 2014
20
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int n, f[1000], e[1000];
  6.  
  7. void Descompunere(int n)
  8. {
  9. int i = 0, fact, exp = 0;
  10. for(fact = 2; n != 1; fact++)
  11. {
  12. while(n % fact == 0)
  13. {
  14. exp++;
  15. n /= fact;
  16. }
  17. if(exp != 0)
  18. {
  19. f[i] = fact;
  20. e[i] = exp;
  21. i++;
  22. }
  23. exp = 0;
  24. }
  25. }
  26.  
  27. int Prim(int n)
  28. {
  29. /*for(int i = 2; i*i <= n; i++)
  30. if(n % i == 0)
  31. return 0;
  32. return 1;*/
  33.  
  34. if(n < 2)
  35. return 0;
  36. Descompunere(n);
  37. if((e[0] == 1) && (f[1] == 0))
  38. return 1;
  39. return 0;
  40. }
  41.  
  42. int Divizori(int n)
  43. {
  44. Descompunere(n);
  45. int div = 1;
  46.  
  47. for(int i = 0; e[i] != 0; i++)
  48. div *= e[i]+1;
  49.  
  50. return div;
  51. }
  52.  
  53. void Afisare(int a[], int n)
  54. {
  55. for(int i = 0; i < n; i++)
  56. cout << a[i] << " ";
  57. cout << "\n\n";
  58. }
  59.  
  60. int main()
  61. {
  62. cin >> n;
  63. Descompunere(n);
  64. Afisare(f, 10);
  65. Afisare(e, 10);
  66.  
  67. if(Prim(n) == 1) cout << n << " este numar prim.\n";
  68. else cout << n << " nu este numar prim.\n";
  69.  
  70. cout << n << " are " << Divizori(n) << " divizori.";
  71. return 0;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement