# Math - Divisor Summation

Mar 15th, 2021
741
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #include <bits/stdc++.h>
2. #define Niloy
3. #define int int64_t
4. #define MAX 1000
5. #define MOD 1e9
6. #define pb push_back
7. #define pairs pair<int, int>
8. #define vi vector<int>
9. #define vb vector<bool>
10. #define vii vector<pairs>
11. #define lb lower_bound
12. #define ub upper_bound
13. #define endl '\n'
14. #define llu unsigned long long
15. using namespace std;
16. /* ----------------------------------------------------------------------------------- */
17.
18. // Input/Output
19. #define fastInput ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
20. #define all(x) x.begin(), x.end()
21.
22. #define scan(a)           scanf("%lld", &a);
23. #define scan2(a, b)       scanf("%lld %lld", &a, &b);
24. #define scan3(a, b, c)    scanf("%lld %lld %lld", &a, &b, &c);
25. #define scan4(a, b, c, d) scanf("%lld %lld %lld %lld", &a, &b, &c, &d);
26.
27. #define scanD(a)          scanf("%lf", &a);
28. #define scanD2(a, b)      scanf("%lf %lf", &a, &b);
29. #define scanD3(a, b, c)   scanf("%lf %lf %lf", &a, &b, &c);
30. #define scanD4(a, b, c, d)scanf("%lf %lf %lf %lf", &a, &b, &c, &d);
31.
32.
33. #define print(a)           printf("%lld\n", a);
34. #define print2(a, b)       printf("%lld %lld\n", a, b);
35. #define print3(a, b, c)    printf("%lld %lld %lld\n", a, b, c);
36. #define print4(a, b, c, d) printf("%lld %lld %lld %lld\n", a, b, c, d);
37.
38. #define printD(a)          printf("%lf\n", a);
39. #define printD2(a, b)      printf("%lf %lf\n", a, b);
40. #define printD3(a, b, c)   printf("%lf %lf %lf\n", a, b, c);
41. #define printD4(a, b, c, d)printf("%lf %lf %lf %lf\n", a, b, c, d);
42. #define printTwoD(a)       printf("%.2lf\n", a);
43.
44. // File I/O
45. #define read(x)  freopen(x, "r", stdin);
46. #define write(x) freopen(x, "w", stdout);
47.
48. // Loops
49. #define rep(i, a, n) for (int i = a; i < n; i++)
50. #define REP(i, a, n) for (int i = a; i <= n; i++)
51. #define rev(i, n, a) for (int i = n - 1; i >= a; i--)
52. #define REV(i, n, a) for (int i = n; i >= a; i--)
53. #define inputArray(a,n) rep(i, 0, n) cin >> a[i];
54. #define copyArray(a,temp,n) rep(i, 0, n) temp[i]=a[i];
55. #define printArray(a,n) rep(i, 0, n) cout << a[i] << " "; cout << endl;
56.
57. /* ----------------------------------------------------------------------------------- */
58.
59. #define Cases  cout << "Case " << ++Case << ": ";
60. #define __test int tt; int Case=0; cin >> tt; while(tt--)
61. #define showTime cerr << "time = " << (clock() / CLOCKS_PER_SEC) << " sec" << '\n';
62.
63. #define dbgA2(A, n, m) {cout<<"--> "<<#A<<" = \n";rep(i, 0, n){rep(j, 0, m){cout<<A[i][j]<<"";}cout<<"\n";}cout<<"\n";}
64. #define dbgA(A, n) {cout<<" --> "<<#A<<" = (";rep(i, 0, n)cout<<A[i]<<" ";cout<<")\n";}
65. #define dbg(args...) {string sss(#args);sss+=',';cout<<" --> ";debugger::call(all(sss), args);cout<<"\n";}
66.
67. /* ----------------------------------------------------------------------------------- */
68.
69. int gcd(int n, int m) { return m ? gcd(m, n % m) : n; }
70. int lcm(int n, int m) { return n / gcd(n, m) * m; }
71.
72. struct debugger {
73.     typedef string::iterator si;
74.     static void call(si it, si ed) {}
75.     template<typename T, typename ... aT>
76.     static void call(si it, si ed, T a, aT... rest) {
77.         string b;
78.         for(; *it!=','; ++it)
79.             if(*it!=' ')
80.                 b+=*it;
81.         cout << b << "=" << a << " ";
82.         call(++it, ed, rest...);
83.     }
84. };
85.
86. /* ----------------------------------------------------------------------------------- */
87. void input() {
88. #ifdef Niloy
90.     write("output.txt");
91. #endif
92. }
93.
94. /* ----------------------------------------------------------------------------------- */
95.
96.
97.
98. void solve() {
99.     int n;
100.     scan(n);
101.     int sum = 0;
102.     if (n == 1) {
103.         cout << 0 << endl;
104.         return;
105.     }
106.     for (int i = 2; i <= sqrt(n); i++) {
107.         if (n % i == 0) {
108.             if (i == (n / i)) {
109.                 sum += i;
110.             } else {
111.                 sum += (i + n / i);
112.             }
113.         }
114.     }
115.     print(sum + 1);
116. }
117.
118. int32_t main() {
119.     // input();
120.     // fastInput;
121.     // solve();
122.
123.     __test {
124.         solve();
125.     }
126.
127.     // showTime;
128.     return 0;
129. }
130.
RAW Paste Data