Advertisement
Farjana_akter

Untitled

Feb 19th, 2020
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long int ll;
  4. bool mark[2000000];
  5. vector<ll>isprime;
  6.  
  7.  
  8. void sieve()
  9. {
  10. mark[0]=true;
  11. mark[1]=true;
  12. for(ll i=2; i*i<=1000005; i++)
  13. {
  14. if(mark[i]==false)
  15. {
  16. for(ll j=i*i; j<=1000005; j+=i)
  17. {
  18. mark[j]=true;
  19. }
  20. }
  21. }
  22. for(ll i=2;i<1000005;i++)
  23. {
  24. if(mark[i]==false)
  25. isprime.push_back(i);
  26. }
  27. }
  28.  
  29.  
  30.  
  31. bool factor(ll n,ll m)
  32. {
  33. ll a,b,c,d,i,j,k;
  34. a=sqrt(m);
  35. vector< pair<ll,ll> >v;
  36. for(i=0; i<isprime.size(); i++)
  37. {
  38. if(isprime[i]>a)
  39. break;
  40. if(m%isprime[i]==0)
  41. {
  42. ll cnt=0;
  43. while(m%isprime[i]==0)
  44. {
  45. m/=isprime[i];
  46. cnt++;
  47. }
  48. v.push_back(make_pair(isprime[i],cnt));
  49. }
  50. }
  51. if(m>1)
  52. v.push_back(make_pair(m,1));
  53.  
  54.  
  55. for(auto t: v)
  56. {
  57. c=n;
  58. ll cnt=0;
  59. while(c)
  60. {
  61. c/=t.first;
  62. cnt+=c;
  63. }
  64. if(cnt<t.second)
  65. return false;
  66. }
  67. return true;
  68. }
  69.  
  70.  
  71.  
  72. int main()
  73. {
  74. sieve();
  75. ll n,m,i,j,k;
  76. while(cin>>n>>m)
  77. {
  78. if(factor(n,m)==true)
  79. cout<<m<<" divides "<<n<<"!"<<endl;
  80. else
  81. cout<<m<<" does not divide "<<n<<"!"<<endl;
  82. }
  83. return 0;
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement