Source Code
//in the name of Allah

#include<bits/stdc++.h>

#define ll long long
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define SPEED ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define sz size()
#define all(x) x.begin(),x.end()
#define OO 1e16
#define R return
#define Test int TT;cin>>TT;for(int T=1;T<=TT;T++)

using namespace std;
const ll N = 200010,Mod = 1e9 + 7;
ll n,m,a[N];
ll x,y,k;
string s;

ll Calc(int n)
{
    R x * n  + (n / k) * y - (n%k == 0) * y;
}

ll Solve(ll n)
{
    ll S = (n * (n + 1) / 2);
    ll Res1 = x * S;
    ll z = n / k - (n%k == 0);
    ll S2 = (z * (z + 1)/2);

    ll Res2 = k * S2;
    ll zz = k - (n%k);
    Res2 -= z * zz;
    Res2 *= y;
    Res1 %= Mod;
    Res2 %= Mod;
    R (Res1 + Res2)%Mod;
}

int main()
{
    SPEED;
    ll l,r;
    cin >> l >> r >> x >> y >> k;
    ll Res = 0;
    /*for(int i=1;i<=r;i++)
        Res += Calc(i);*/
    ll Ans = Solve(r);
    if(l != 1)
        Ans -= Solve(l-1);
    Ans %= Mod;
    Ans += Mod;
    Ans %= Mod;
    cout << Ans << endl;
    R 0;
}
Copy
Practice Practice yaman_alwaza
GNU G++17
1 ms
480 KB
Wrong Answer