fork download
  1. // TEMPLATE - START
  2. // ----------------------------------------------------
  3. // DEFINES - START
  4. #include <bits/stdc++.h>
  5. #define FAST \
  6.   ios_base::sync_with_stdio(0); \
  7.   cin.tie(0); \
  8.   cout.tie(0);
  9. // Strings
  10. #define nl "\n"
  11. #define YES cout << "YES\n"
  12. #define NO cout << "NO\n"
  13. #define yn(x) \
  14.   if (x) \
  15.   cout << "YES\n"; \
  16.   else \
  17.   cout << "NO\n";
  18. #define yns(x, s1, s2) \
  19.   if (x) \
  20.   cout << s1 << "\n"; \
  21.   else \
  22.   cout << s2 << "\n";
  23. #define fail(cond) \
  24.   if (cond) \
  25.   { \
  26.   NO; \
  27.   return; \
  28.   }
  29. #define success(cond) \
  30.   if (cond) \
  31.   { \
  32.   YES; \
  33.   return; \
  34.   }
  35. // Types
  36. #define ll long long
  37. #define ull unsigned long long
  38. #define vl vector<ll>
  39. #define pll pair<ll, ll>
  40. #define vpll vector<pair<ll, ll>>
  41. #define all(x) (x).begin(), (x).end()
  42. // Loops
  43. #define lp(i, a, b) for (int i = (a); i < (b); i++)
  44. #define rlp(i, a, b) for (int i = (b) - 1; i >= (a); i--)
  45. #define readlp(arr, n) \
  46.   lp(i, 0, n) cin >> arr[i];
  47. #define writelp(arr, n) \
  48.   lp(i, 0, n) cout << arr[i] << " "; \
  49.   cout << nl;
  50. #define vv \
  51.   ll n; \
  52.   cin >> n; \
  53.   vl v(n); \
  54.   readlp(v, v.size());
  55. // DEFINES - END
  56. // ----------------------------------------------------
  57. using namespace std;
  58. // ----------------------------------------------------
  59. // ALGORITHMS - START
  60. // Binary Search Custom:
  61. // To Find...,Logical Condition,If Condition is Met...,Return Value
  62. // Lower Bound (First element ≥x),arr[m] >= x,r = m,r
  63. // Upper Bound (First element >x),arr[m] > x,r = m,r
  64. // Last element <x,arr[m] < x,l = m,l
  65. // Last element ≤x,arr[m] <= x,l = m,l
  66.  
  67. int lowerBound(vector<ll> &v, ll x)
  68. {
  69. int l = -1, r = v.size();
  70. while (r > l + 1)
  71. {
  72. int m = l + (r - l) / 2;
  73. ll curr = v[m];
  74. if (curr >= x)
  75. r = m;
  76. else
  77. l = m;
  78. }
  79. return r;
  80. }
  81. // ALGORITHMS - END
  82. // ----------------------------------------------------
  83. // TEMPLATE END
  84.  
  85. // ====================================================
  86.  
  87. // Boody's Code
  88. // 2026-07-30, 21:35:44
  89. // CSES - CSES Problem Set
  90. // Sum of Divisors
  91. // https://c...content-available-to-author-only...s.fi/problemset/task/1082
  92. // Time limit: 00, Memory limit: 1
  93. // status:
  94. // Time taken:
  95.  
  96. // ----------------------------------------------------
  97.  
  98. ll mod = 1000000007;
  99. ll modmul(ll a, ll b)
  100. {
  101. return (((a % mod) * (b % mod)) % mod);
  102. }
  103.  
  104. void solve()
  105. {
  106. ll n, inv2 = (mod + 1) / 2;
  107. cin >> n;
  108. ll sum = (n - 1 + modmul(modmul(n, (n + 1)), inv2)) % mod, a, b, c;
  109. for (ll i = 2; i * i <= n; i++)
  110. {
  111. a = n / i, b = modmul(modmul(a, (a + 1)), inv2), c = modmul(modmul(i, (i + 1)), inv2);
  112. sum += (modmul(a - i + 1, i) + ((b - c + mod) % mod)) % mod, sum %= mod;
  113. }
  114. cout << sum << nl;
  115. }
  116.  
  117. int main()
  118. {
  119. #ifndef ONLINE_JUDGE
  120. freopen("/home/rodex/rubuntu/CS/CP/input.txt", "r", stdin);
  121. freopen("/home/rodex/rubuntu/CS/CP/output.txt", "w", stdout);
  122. #endif
  123. FAST;
  124.  
  125. int t = 1;
  126. // cin >> t;
  127. while (t--)
  128. solve();
  129. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
-1