Maruf_Hasan

divisors.cpp

Oct 18th, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define M 1000000
  5.  
  6. bool mark[M];
  7.  
  8. vector<int>prime;
  9.  
  10. void sieve()
  11. {
  12. int i,j;
  13. prime.push_back(2);
  14. for(i=3;i*i<M;i+=2)
  15. {
  16. if(mark[i]==false)
  17. {
  18. for(j=i*i;j<M;j+=2*i)
  19. mark[j]=true;
  20. }
  21. }
  22. for(i=3;i<M;i+=2)
  23. {
  24. if(mark[i]==false)
  25. prime.push_back(i);
  26. }
  27.  
  28. }
  29.  
  30.  
  31. int divisors(int n)
  32. {
  33. int divisor=1;
  34. int k=n;
  35. for(int i=0;prime[i]<k;i++)
  36. {
  37. if(n%prime[i]==0)
  38. {
  39. int count=1;
  40. while(n%prime[i]==0)
  41. {
  42. n/=prime[i];
  43. count++;
  44. }
  45. divisor*=count;
  46. }
  47. }
  48.  
  49. return divisor;
  50. }
  51.  
  52. int main()
  53. {
  54. int n,i,k;
  55. sieve();
  56. scanf("%d",&n);
  57. k=divisors(n);
  58.  
  59. printf("%d\n",k);
  60.  
  61. return 0;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment