Advertisement
a53

Fantastice

a53
Jan 24th, 2017
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. #include <fstream>
  2. using namespace std;
  3. ifstream f("fantastice.in");
  4. ofstream g("fantastice.out");
  5.  
  6.  
  7. int nr_div(int n)
  8. {
  9. int i,nr=0;
  10. for(i=1;i*i<n;i++)
  11. if(n%i==0)
  12. nr+=2;
  13. if (i*i==n)
  14. ++nr;
  15. return nr;
  16. }
  17.  
  18. bool prim(int n)
  19. {
  20. if(n<2)
  21. return false;
  22. ///numerele pare mai mari decat 2 nu sunt prime
  23. if(n % 2 == 0 && n > 2)
  24. return false;
  25. bool eprim=true;/// Presupunem ca e prim
  26. ///cautam un divizor impar
  27. for(int d=3;d*d<=n&&eprim;++d)
  28. if(n%d==0) /// daca il gasim
  29. eprim=false; ///numarul n nu este prim
  30. if(eprim)
  31. return true;
  32. else
  33. return false;
  34. }
  35.  
  36.  
  37. int main()
  38. {
  39. int n,x,fantastice=0;
  40. f>>n;
  41. while(n--)
  42. {
  43. f>>x;
  44. if(prim(x))
  45. ++fantastice;
  46. else
  47. if(prim(nr_div(x)))
  48. ++fantastice;
  49. }
  50. g<<fantastice;
  51. return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement