fork download
  1. #include <bits/stdc++.h>
  2.  
  3. #define el '\n'
  4. #define fi first
  5. #define sec second
  6. #define pb push_back
  7. #define ll long long
  8. #define pii pair<int,int>
  9. #define sz(v) (int)(v).size()
  10. #define all(v) (v).begin(),(v).end()
  11. #define FOR(i, a, b) for(int i = (a), _b = (b); i <= _b; i++)
  12. #define REP(i, a, b) for(int i = (b), _a = (a); i >= _a; i--)
  13.  
  14. using namespace std;
  15.  
  16. const int MOD = 1e9 + 7;
  17. const int inv2 = (MOD + 1) / 2;
  18.  
  19. inline int cong(ll x, ll y){
  20. ll z = x + y;
  21. while(z >= MOD) z -= MOD;
  22. return z;
  23. }
  24.  
  25. inline int nhan(ll x, ll y){
  26. return (x * y) % MOD;
  27. }
  28.  
  29. int tinh_tong(ll l, ll r){
  30. ll one = (r - l + 1 + MOD) % MOD;
  31. ll two = cong(l, r);
  32. return nhan(nhan(one, two), inv2);
  33. }
  34.  
  35. ll tinh(ll n){
  36. ll first_pos = 1, res = 0;
  37.  
  38. while(first_pos <= n){
  39. ll val = n / first_pos, last_pos;
  40.  
  41. if(!val) last_pos = n;
  42. else last_pos = n / val;
  43.  
  44. res = cong(res, nhan(tinh_tong(first_pos, last_pos), val));
  45.  
  46. first_pos = last_pos + 1;
  47. }
  48.  
  49. return res;
  50. }
  51.  
  52. int main(){
  53. ios_base::sync_with_stdio(0);
  54. cin.tie(0);
  55.  
  56. ll l, r;
  57. cin >> l >> r;
  58.  
  59. cout << (tinh(r) - tinh(l - 1)) + MOD % MOD;
  60. }
  61.  
Success #stdin #stdout 1.29s 5316KB
stdin
Standard input is empty
stdout
-291511667