Advertisement
erfanul007

UVa 10139

Dec 16th, 2019
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.02 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #pragma GCC optimize("Ofast,no-stack-protector")
  5. #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
  6. #pragma GCC optimize("unroll-loops")
  7.  
  8. typedef unsigned long long ull;
  9. typedef long long ll;
  10. typedef long double lld;
  11. typedef vector<int> vi;
  12. typedef vector<ll> vll;
  13. typedef vector<vi> vvi;
  14. typedef pair<int,int > pii;
  15. typedef vector< pii > vpii;
  16. typedef set<int> sti;
  17.  
  18. #define sc scanf
  19. #define pf printf
  20. #define sci(n) scanf("%d",&n)
  21. #define scii(n,m) scanf("%d %d",&n,&m)
  22. #define scl(n) scanf("%lld",&n)
  23. #define scd(n) scanf("%lf",&n)
  24. #define scs(s) scanf("%s",s)
  25. #define pfi(n) printf("%d",n)
  26. #define pfl(n) printf("%lld",n)
  27. #define pff(n) cout<<n
  28. #define spc printf(" ")
  29. #define line printf("\n")
  30. #define loop(i,x,y) for(int i=int(x); i<=int(y); i++)
  31. #define rloop(i,y,x) for(int i=int(y); i>=int(x); i--)
  32. #define cspf(i) printf("Case %d: ", i)
  33. #define vout(v) for(int w=0;w<v.size();w++){if(w) cout<<' '; cout<<v[w];}
  34. #define clr(a,x) memset(a,x,sizeof(a))
  35. #define tp(v,j) get<j>(v)
  36. #define pb push_back
  37. #define mp make_pair
  38. #define mt make_tuple
  39. #define ff first
  40. #define ss second
  41. #define all(v) v.begin(),v.end()
  42. #define rall(v) v.rbegin(),v.rend()
  43. #define read() freopen("input.txt", "r", stdin)
  44. #define write() freopen("output.txt", "w", stdout)
  45. #define fastIO() ios_base::sync_with_stdio(false); cin.tie(NULL);
  46. /// Constants
  47. #define eps 1e-6
  48. #define PI acos(-1.0) // 3.1415926535897932
  49. #define MAX (int)1000000009
  50.  
  51. int GCD(int a, int b) { return b == 0 ? a : GCD(b , a % b); }
  52. ll LCM(ll a, ll b) { return a * (b/GCD(a, b)); }
  53.  
  54.  
  55. vpii Bprime(int b)
  56. {
  57. vpii bp;
  58. for(int i=2;i<=b/i;i++){
  59. if(b%i==0){
  60. int cnt=0;
  61. while(b%i==0){
  62. b/=i;
  63. cnt++;
  64. }
  65. bp.pb(mp(i,cnt));
  66. }
  67. }
  68. if(b>1) bp.pb(mp(b,1));
  69. return bp;
  70. }
  71.  
  72. int cntpairs(int n,pii x)
  73. {
  74. int cnt=0;
  75. while(n){
  76. cnt+=n/x.ff;
  77. n/=x.ff;
  78. }
  79. return cnt/x.ss;
  80. }
  81.  
  82. int zeros(int n,vpii bp)
  83. {
  84. if(!n) return 0;
  85. int mn = INT_MAX;
  86. loop(i,0,bp.size()-1){
  87. mn = min(mn,cntpairs(n,bp[i]));
  88. }
  89. return mn;
  90. }
  91.  
  92. int main()
  93. {
  94. #ifdef VAMP
  95. clock_t tStart = clock();
  96. freopen("input.txt", "r", stdin);
  97. freopen("output.txt", "w", stdout);
  98. #endif
  99.  
  100. int n,b;
  101. while(~scii(n,b)){
  102. if(b==1 || zeros(n,Bprime(b))) pf("%d divides %d!\n",b,n);
  103. else pf("%d does not divide %d!\n",b,n);
  104. }
  105.  
  106. #ifdef VAMP
  107. fprintf(stderr, "\n>> Runtime: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
  108. #endif
  109.  
  110. return 0;
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement