fork download
  1. #include <bits/stdc++.h>
  2. #include <bitset>
  3. using namespace std;
  4. #define int long long
  5. #define dd double
  6. #define ld long double
  7. #define ull unsigned long long
  8. #define yes cout << "YES\n"
  9. #define no cout << "NO\n"
  10. #define el "\n"
  11. #define Arwa ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  12. #define fix(x) cout << fixed << setprecision(x)
  13. #define all(v) v.begin(),v.end()
  14. #define dpp(arr,val) memset(arr,val,sizeof(arr))
  15. #define mod 1e9+7
  16. const int N = 1e5 + 5;
  17. //todo اى ويل بريبير ماى بيبرز تو بى ذا بيست ان زيس وورلد
  18. //prime factorization
  19. map<int,int>pf;
  20. void primeFact(int n)
  21. {
  22.  
  23. for(int i=2;i*i<=n;i++)
  24. {
  25. if(n%i==0)
  26. {
  27. int cnt=0;
  28. while(n%i==0) n/=i,cnt++;
  29. pf[i]+=cnt;
  30. }
  31. }
  32. if(n>1) pf[n]+=1;
  33. }
  34. void HereWeGoAgain()
  35. {
  36. pf.clear();
  37. string s;
  38. cin>>s;
  39. int k=0,num=0;
  40. for(int i=0;i<s.length();i++)
  41. {
  42. if(s[i]=='!') k++;
  43. else
  44. {
  45. num*=10;
  46. num+=(s[i]-'0');
  47. }
  48. }
  49. // cout<<num<<' '<<k<<el;
  50. for(int i=num;i>=1;i-=k)
  51. {
  52. primeFact(i);
  53. }
  54. int dividers=1;
  55. for(auto it:pf)// cout<<it.first<<' '<<it.second<<' '; cout<<el;
  56. {
  57. if(it.second)
  58. {
  59. if(dividers>LONG_MAX/(it.second+1)) { cout<<"Infinity\n"; return; }
  60. else dividers*=(it.second+1);
  61. }
  62. }
  63. cout<<dividers<<'\n';
  64. }
  65.  
  66. int32_t main()
  67. {
  68.  
  69. Arwa
  70. int t=1;
  71. cin>>t;
  72. for(int i=1;i<=t;i++)
  73. {
  74. cout<<"Case "<<i<<": ";
  75. HereWeGoAgain();
  76. }
  77. return 0;
  78. }
  79.  
  80.  
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
Case 1: 1