Source Code
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int MAXN = 1e2 + 5;
const int MOD = 1e9 + 7;
ll n,k,x,y,l,r;

ll get(ll n)
{
   ll p1 = n * (n + 1) >> 1;
   p1%=MOD;
   p1*=x;
   p1%=MOD;
   ll p2 = (n - 1) / k;
   ll nextMul = (p2 + 1) * k - 1;
   ll sump2 = p2 * (p2 + 1) / 2;
   sump2%=MOD;
   sump2*=k;
   sump2%=MOD;
   sump2*=y;
   sump2%=MOD;
   ll mul = (n - 1) / k;
   ll ansP2 = sump2 - (mul * y * (nextMul - n + 1)) % MOD;
   ansP2%=MOD;
   return p1 + ansP2%MOD;


}

int main()
{
    

cin >> l >> r >> x >> y >> k;

cout << (get(r) - get(l - 1) + MOD) % MOD;


 
    
}
Copy
Practice Practice DoeJohn
GNU G++17
2 ms
256 KB
Accepted