Saleh127

UVA 10139

Jul 19th, 2020
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define test int t; cin>>t; while (t--)
  4. #define ll long long int
  5. #define fellow_junior ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  6. #define maX 1000008
  7. vector<ll>p;
  8. bool marked[maX];
  9. void sieve()
  10. {
  11. for(ll i=4;i<=maX;i+=2)
  12. {
  13. marked[i]=1;
  14. }
  15. p.push_back(2);
  16. for(ll i=3;i<=maX;i+=2)
  17. {
  18. if(marked[i]==0)
  19. {
  20. p.push_back(i);
  21. for(ll j=i*i; j<=maX; j+=i+i)
  22. {
  23. marked[j]=1;
  24. }
  25. }
  26. }
  27. }
  28. ll divoffact(ll nn,ll mm)
  29. {
  30. ll i,j=0;
  31. for(i=mm;i<=nn;i*=mm)
  32. {
  33. j+=(nn/i);
  34. }
  35. return j;
  36. }
  37. int main()
  38. {
  39. fellow_junior
  40. sieve();
  41. ll a,c,d,e,fact,fact2,i,j,k,l;
  42. while(cin>>a>>c)
  43. {
  44. j=1;
  45. e=c;
  46. for(i=0;p[i]*p[i]<=c && i<p.size();i++)
  47. {
  48. d=p[i];
  49. fact=0;
  50. while(c%d==0)
  51. {
  52. c/=d;
  53. fact++;
  54. }
  55. fact2=divoffact(a,d);
  56. if(fact2<fact)
  57. {
  58. j=0;
  59. break;
  60. }
  61. }
  62. if(c!=1 && c>a)
  63. {
  64. j=0;
  65. }
  66. if(j) cout<<e<<" divides "<<a<<"!"<<endl;
  67. else cout<<e<<" does not divide "<<a<<"!"<<endl;
  68. }
  69. return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment