Advertisement
a53

prim013

a53
Jan 5th, 2018
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. #include <fstream>
  2. #include <bitset>
  3. #define N 10000001
  4. using namespace std;
  5. bitset <N> prim;
  6.  
  7. void Ciur()
  8. {
  9. prim[0]=prim[1]=1; /// Ciurul lui Eratostene
  10. for(int i=2;i*i<N;++i)
  11. if(prim[i]==0)
  12. for(int j=2;i*j<N;++j)
  13. prim[i*j]=1;
  14. }
  15.  
  16. int nrdivizori(int n)
  17. {
  18. int nrdiv=1,j,exp=0;
  19. bool ok=false;
  20. while(n%2==0)
  21. n/=2,++exp;
  22. nrdiv*=(exp+1);
  23. for(j=3;j*j<=n&&n!=1&&!ok;j+=2)
  24. {
  25. exp=0;
  26. while(n%j==0)
  27. {
  28. n/=j;
  29. ++exp;
  30. }
  31. nrdiv*=(exp+1);
  32. if(n==1)
  33. ok=true;
  34. }
  35. if(n>1)
  36. nrdiv*=2;
  37. return nrdiv;
  38. }
  39.  
  40. int main()
  41. {
  42. ifstream f("prim013.in");
  43. Ciur();
  44. int n;
  45. f>>n;
  46. int x,nr=0;
  47. for(int i=0;i<n;++i)
  48. {
  49. f>>x;
  50. if(!prim[nrdivizori(x)])
  51. ++nr;
  52. }
  53. f.close();
  54. ofstream g("prim013.out");
  55. g<<nr;
  56. g.close();
  57. return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement