Advertisement
Saleh127

UVA 11347

Feb 11th, 2021
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. ///UVA 11347 idea: prime power factorization && number of div;
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. #define ll long long
  5. #define test int t; cin>>t; for(int cs=1;cs<=t;cs++)
  6. #define inf 1e18
  7. vector<ll>prime;
  8. map<ll,ll>fre;
  9.  
  10. void fact(ll n)
  11. {
  12. if(n%2==0)
  13. {
  14. if(fre[2]==0) prime.push_back(2);
  15. while(n%2==0)
  16. {
  17. fre[2]++;
  18. n/=2;
  19. }
  20. }
  21. for(ll i=3; i*i<=n; i+=2)
  22. {
  23. if(n%i==0)
  24. {
  25. if(fre[i]==0) prime.push_back(i);
  26. while(n%i==0)
  27. {
  28. fre[i]++;
  29. n/=i;
  30. }
  31. }
  32. }
  33. if(n>1)
  34. {
  35. if(fre[n]==0) prime.push_back(n);
  36. fre[n]++;
  37. }
  38. }
  39.  
  40.  
  41. int main()
  42. {
  43. ios_base::sync_with_stdio(0);
  44. cin.tie(0);
  45. cout.tie(0);
  46.  
  47.  
  48. test
  49. {
  50.  
  51. ll n=0,m,i,j,k=0,l=0,ans=1;
  52. string a;
  53. cin>>a;
  54.  
  55. for(i=0; i<a.size(); i++)
  56. {
  57. if(a[i]=='!') l++;
  58. else
  59. {
  60. n*=10;
  61. n+=(a[i]-'0');
  62. }
  63. }
  64.  
  65. prime.clear();
  66. fre.clear();
  67.  
  68. for(i=n; i>1; i-=l)
  69. {
  70. fact(i);
  71. }
  72.  
  73. for(i=0; i<prime.size(); i++)
  74. {
  75. ans*=(fre[prime[i]]+1);
  76.  
  77. if(ans> inf)
  78. {
  79. k=1;
  80. break;
  81. }
  82. }
  83.  
  84. cout<<"Case "<<cs<<": ";
  85.  
  86. if(k) cout<<"Infinity"<<endl;
  87. else cout<<ans<<endl;
  88. }
  89.  
  90. return 0;
  91. }
  92.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement