Advertisement
erfanul007

UVa 10484

Dec 26th, 2019
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.12 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 pair<ll,ll > pll;
  16. typedef vector< pii > vpii;
  17. typedef vector< pll > vpll;
  18. typedef set<int> sti;
  19.  
  20. #define sc scanf
  21. #define pf printf
  22. #define sci(n) scanf("%d",&n)
  23. #define scii(n,m) scanf("%d %d",&n,&m)
  24. #define scl(n) scanf("%lld",&n)
  25. #define scd(n) scanf("%lf",&n)
  26. #define scs(s) scanf("%s",s)
  27. #define pfi(n) printf("%d",n)
  28. #define pfl(n) printf("%lld",n)
  29. #define pff(n) cout<<n
  30. #define spc printf(" ")
  31. #define line printf("\n")
  32. #define loop(i,x,y) for(int i=int(x); i<=int(y); i++)
  33. #define rloop(i,y,x) for(int i=int(y); i>=int(x); i--)
  34. #define cspf(i) printf("Case %d: ", i)
  35. #define vout(v) for(int w=0;w<v.size();w++){if(w) cout<<' '; cout<<v[w];}
  36. #define clr(a,x) memset(a,x,sizeof(a))
  37. #define tp(v,j) get<j>(v)
  38. #define pb push_back
  39. #define mp make_pair
  40. #define mt make_tuple
  41. #define ff first
  42. #define ss second
  43. #define all(v) v.begin(),v.end()
  44. #define rall(v) v.rbegin(),v.rend()
  45. #define read() freopen("input.txt", "r", stdin)
  46. #define write() freopen("output.txt", "w", stdout)
  47. #define fastIO() ios_base::sync_with_stdio(false); cin.tie(NULL);
  48. /// Constants
  49. #define eps 1e-6
  50. #define PI acos(-1.0) // 3.1415926535897932
  51. #define MAX (ll)2147483647
  52. #define MAXn (ll)100001
  53.  
  54. int GCD(int a, int b) { return b == 0 ? a : GCD(b , a % b); }
  55. ll LCM(ll a, ll b) { return a * (b/GCD(a, b)); }
  56.  
  57. bool isprime[MAXn+1];
  58. vi prime;
  59.  
  60. void seive()
  61. {
  62. clr(isprime,true);
  63. isprime[0]=false;
  64. isprime[1]=false;
  65. for(int i=4;i<MAXn;i+=2) isprime[i]=false;
  66. for(int i=3;i*i<MAXn;i+=2){
  67. if(!isprime[i]) continue;
  68. for(int j=i*i;j<MAXn;j+=2*i) isprime[j]=false;
  69. }
  70.  
  71. prime.pb(2);
  72. for(int i=3;i<MAXn;i+=2){
  73. if(isprime[i]) prime.pb(i);
  74. }
  75. }
  76.  
  77. int ncnt[101];
  78.  
  79. void fact_factors(int n)
  80. {
  81. for(int i=0;prime[i]<=n;i++){
  82. int x = n;
  83. int c=0;
  84. while(x){
  85. c+=x/prime[i];
  86. x/=prime[i];
  87. }
  88. ncnt[prime[i]]=c;
  89. }
  90. }
  91.  
  92. vpii facts;
  93. void factors(int d)
  94. {
  95. for(int i=0;prime[i]<=d/prime[i];i++){
  96. if(d%prime[i]==0){
  97. int c=0;
  98. while(d%prime[i]==0){
  99. d/=prime[i];
  100. c++;
  101. }
  102. facts.pb(mp(prime[i],c));
  103. }
  104. }
  105. if(d>1) facts.pb(mp(d,1));
  106. }
  107.  
  108.  
  109. int main()
  110. {
  111. #ifdef VAMP
  112. clock_t tStart = clock();
  113. freopen("input.txt", "r", stdin);
  114. freopen("output.txt", "w", stdout);
  115. #endif
  116.  
  117. seive();
  118.  
  119. ll n,d;
  120. while(1){
  121. sc("%lld %lld",&n,&d);
  122. if(!d) break;
  123. d = abs(d);
  124. if(!n){
  125. if(d==1) pf("1\n");
  126. else pf("0\n");
  127. continue;
  128. }
  129. clr(ncnt,0);
  130. facts.clear();
  131. fact_factors(n);
  132. factors(d);
  133. ll ans = 1LL;
  134. int j=0;
  135. for(int i=2;i<=n;i++){
  136. if(j<facts.size()){
  137. int x = facts[j].ff;
  138. int y = facts[j].ss;
  139. if(x==i){
  140. if(ncnt[i]>=y) ans*=(ll)(ncnt[i]+1-y);
  141. else ans=0LL;
  142. j++;
  143. }
  144. else ans*=(ll)(ncnt[i]+1);
  145. }
  146. else ans*=(ll)(ncnt[i]+1);
  147. }
  148. if(j<facts.size()) ans=0LL;
  149. pfl(ans);line;
  150. }
  151.  
  152.  
  153. #ifdef VAMP
  154. fprintf(stderr, "\n>> Runtime: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
  155. #endif
  156.  
  157. return 0;
  158. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement