fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. const ll p = 1e9 + 7;
  5. ll n, L, R, q;
  6.  
  7.  
  8. ll add(ll x, ll y){ return (x % p + y % p) % p; }
  9. ll mul(ll x, ll y){ return (x % p * y % p) % p; }
  10.  
  11. ll Pow(ll a, ll b){
  12. if(!b) return 1;
  13. ll cur = Pow(a, b / 2);
  14. cur = mul(cur, cur);
  15. if(b % 2 != 0) cur = mul(cur, a);
  16. return cur;
  17. }
  18. const ll inv = Pow(2, p - 2);
  19.  
  20. ll C(ll x){
  21. if(x < 2) return 0LL;
  22. return mul(x, mul(x - 1, inv));
  23. }
  24.  
  25. int main(){
  26. freopen("love.inp", "r", stdin);
  27. freopen("love.out", "w", stdout);
  28. cin >> q;
  29. while(q--){
  30. cin >> L >> R >> n;
  31. ll a = add(C(R - L + 1), R - L + 1);
  32. ll newL = (L - 1) / n, newR = R / n;
  33. ll b = add(C(newR - newL), (newR - newL));
  34. cout << ((a - b) % p + p) % p << endl;
  35. }
  36. }
  37.  
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
Standard output is empty