Advertisement
Guest User

jeijui

a guest
Feb 22nd, 2020
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. #include <fstream>
  2.  
  3. using namespace std;
  4.  
  5. ifstream f("prim013.in");
  6. ofstream g("prim013.out");
  7.  
  8. int n,nr;
  9. int nrdiv(int x)
  10. {
  11. int ct=1,k=0;
  12. while(x%2==0)
  13. {
  14. k++;
  15. x/=2;
  16. }
  17. ct=k+1;
  18. for(int i=3;i*i<=x;i+=2)
  19. {
  20. k=0;
  21. while(x%i==0)
  22. {
  23. k++;
  24. x/=i;
  25. }
  26. ct*=(k+1);
  27. }
  28. if(x>1)
  29. ct*=2;
  30. return ct;
  31. }
  32. int prim(int x)
  33. {
  34. if(x==2)
  35. return 1;
  36. if(x<2 or x%2==0)
  37. return 0;
  38. for(int i=3;i*i<=x;i+=2)
  39. if(x%i==0)
  40. return 0;
  41. return 1;
  42. }
  43. int main()
  44. {
  45. f >> n;
  46. for(int i=1;i<=n;i++)
  47. {
  48. int a;
  49. f >> a;
  50. if(prim(nrdiv(a)))
  51. nr++;
  52. }
  53. g << nr;
  54.  
  55. return 0;
  56.  
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement