Saleh127

UVA 10791.cpp

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