Advertisement
Farjana_akter

Untitled

Feb 15th, 2020
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long int ll;
  4.  
  5.  
  6. int main()
  7. {
  8. ll n,i,j,k,cas=1;
  9. while(cin>>n && n)
  10. {
  11. cout<<"Case "<<cas++<<": ";
  12. ll res=0,cnt=0,a,b,c,d;
  13. a=n;
  14. if(a==1)
  15. {
  16. cout<<2<<endl;
  17. continue;
  18. }
  19. else
  20. {
  21. if(a%2==0)
  22. {
  23. b=1;
  24. while(a%2==0)
  25. {
  26. b*=2;
  27. a/=2;
  28. }
  29. cnt++;
  30. res=b;
  31. }
  32. for(i=3; i*i<=a; i+=2)
  33. {
  34. if(a%i==0)
  35. {
  36. b=1;
  37. while(a%i==0)
  38. {
  39. b*=i;
  40. a/=i;
  41. }
  42. cnt++;
  43. res+=b;
  44. }
  45. }
  46. if(a>1)
  47. {
  48. res+=a;
  49. cnt++;
  50. }
  51. if(cnt==1)
  52. res=n+1;
  53. cout<<res<<endl;
  54. }
  55. }
  56. return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement