fork(2) download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define getchar_unlocked getchar()
  5.  
  6. void fastscan(ll &x)
  7. {
  8. bool neg=false;
  9. register ll c;
  10. x =0;
  11. c=getchar();
  12. if(c=='-')
  13. {
  14. neg = true;
  15. c=getchar();
  16. }
  17. for(;(c>47 && c<58);c=getchar())
  18. x = (x<<1) + (x<<3) +c -48;
  19. if(neg)
  20. x *=-1;
  21. }
  22.  
  23. ll gcd(ll u,ll v)
  24. {
  25. ll k=0,t=0,i;
  26. while (!(u&1) && !(v&1))
  27. {
  28. k++;
  29. u>>=1;
  30. v>>=1;
  31. }
  32. if (u&1)
  33. t=u;
  34. else
  35. t=-v;
  36. do
  37. {
  38. while (!(t&1))
  39. t>>=1;
  40. if (t>0)
  41. u=t;
  42. else
  43. v=-t;
  44. t=u-v;
  45. }while (t);
  46. for (i=0;i<k;i++)
  47. u<<=1;
  48. return(u);
  49. }
  50.  
  51. ll lcm(ll m, ll n)
  52. {
  53. return m / gcd(m, n) * n;
  54. }
  55.  
  56. int main(){
  57. ll t, n, a,b;
  58.  
  59.  
  60. fastscan(t);
  61. while(t--){
  62. fastscan(n);
  63. ll sum =0;
  64. if(n==1){
  65. cout <<"1\n";
  66. } else {
  67. for(ll i=1;i<n;i++){
  68. for(ll j = i+1;j<=n;j++){
  69. if(lcm(i,j)==n){
  70. ll c = i+j;
  71. sum += c;
  72. }
  73. }
  74. }
  75. cout <<sum<<"\n";
  76. }
  77.  
  78. }
  79.  
  80. return 0;
  81.  
  82. }
  83.  
Success #stdin #stdout 0s 3140KB
stdin
Standard input is empty
stdout
Standard output is empty