fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define file(NAME) if (fopen(NAME".inp", "r")) freopen(NAME".inp", "r", stdin), freopen(NAME".out", "w", stdout)
  6. #define FOR(i, a, b) for (int i = (int) a; i <= (int) b; ++i)
  7. #define FOD(i, a, b) for (int i = (int) a; i >= (int) b; --i)
  8.  
  9. #define all(s) (s).begin(), (s).end()
  10. #define pb push_back
  11. #define ll long long
  12. #define fi first
  13. #define se second
  14. #define pii pair<int, int>
  15.  
  16. const int maxn = 1e5 + 5;
  17. const int N = 505;
  18. const int MOD = 1e9 + 7;
  19.  
  20.  
  21. ll n;
  22.  
  23.  
  24.  
  25.  
  26. ll power(ll a, ll b) {
  27. ll res = 1;
  28. while (b) {
  29. if (b & 1) res = (res * a % MOD) % MOD;
  30. a = (a * a) % MOD;
  31. b >>= 1;
  32. }
  33.  
  34. return res;
  35. }
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44. // sum 1 -> n
  45. ll sum(ll n) {
  46. // n * (n + 1) / 2
  47. return (((n%MOD * (n+1)%MOD)%MOD) * power(2, MOD - 2)) % MOD;
  48. }
  49.  
  50.  
  51.  
  52.  
  53. ll calc(ll i, ll j, ll q) {
  54. // (sum(j-1) - sum(i-1)) * q
  55. return ((sum(j-1) - sum(i-1) + MOD)%MOD * q%MOD) % MOD;
  56. }
  57.  
  58.  
  59.  
  60.  
  61. signed main() {
  62. cin.tie(0) -> sync_with_stdio(0);
  63. file("x");
  64.  
  65.  
  66. cin >> n;
  67.  
  68.  
  69. ll ans = 0;
  70.  
  71. ll i = 1;
  72. while (i <= n) {
  73. ll q = n / i;
  74. ll j = n / q + 1;
  75.  
  76. (ans += calc(i, j, q)) %= MOD;
  77.  
  78. i = j;
  79. }
  80.  
  81. cout << ans;
  82. return 0;
  83. }
Success #stdin #stdout 0.54s 5280KB
stdin
736806794367
stdout
640231665