Saleh127

UVA 10856

Sep 17th, 2020
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define test int t; cin>>t; for(int cs=1;cs<=t;cs++)
  5. #define maX 4000
  6.  
  7. vector<ll>p;
  8. ll fact[10000008];
  9. bool marked[maX];
  10.  
  11. void sieve()
  12. {
  13. marked[0]=1;
  14. marked[1]=1;
  15. for(ll i=4;i<=maX;i+=2)
  16. {
  17. marked[i]=1;
  18. }
  19. p.push_back(2);
  20. for(ll i=3;i<=maX;i+=2)
  21. {
  22. if(marked[i]==0)
  23. {
  24. for(ll j=i*i; j<=maX; j+=i+i)
  25. {
  26. marked[j]=1;
  27. }
  28. }
  29. }
  30. for(ll i=3;i<=maX;i+=2)
  31. {
  32. if(marked[i]==0)
  33. {
  34. p.push_back(i);
  35. }
  36. }
  37. }
  38.  
  39. void calculation()
  40. {
  41.  
  42. memset(fact,-1,sizeof fact);
  43. fact[0]=0;
  44. fact[1]=0;
  45.  
  46. ll i,j,k,l,c,d,e,x=0;
  47.  
  48. for(i=2; ;i++)
  49. {
  50. c=0;
  51. d=i;
  52. for(j=0;p[j]*p[j]<=d;j++)
  53. {
  54. if(d%p[j]==0)
  55. {
  56. while(d%p[j]==0)
  57. {
  58. d/=p[j];
  59. c++;
  60. }
  61. }
  62. }
  63.  
  64. if(d>1) c++;
  65. x+=c;
  66. if(x>10000001) break;
  67. fact[x]=i;
  68.  
  69. }
  70.  
  71. }
  72. int main()
  73. {
  74. ios_base::sync_with_stdio(0);
  75. cin.tie(0);cout.tie(0);
  76.  
  77. sieve();
  78. calculation();
  79.  
  80. ll n,z=1;
  81.  
  82. while(cin>>n && n>=0)
  83. {
  84.  
  85. cout<<"Case "<<z++<<": ";
  86.  
  87. if(fact[n]==-1)
  88. {
  89. cout<<"Not possible."<<endl;
  90. }
  91. else cout<<fact[n]<<"!"<<endl;
  92. }
  93.  
  94.  
  95. return 0;
  96. }
  97.  
Advertisement
Add Comment
Please, Sign In to add comment