Source Code
#include "bits/stdc++.h"
using namespace std;
typedef long long ll; 
#define endl '\n';
#define mp make_pair
#define pb push_back

ll const mod=1e9+7;
ll l,r,x,y,k;
ll calc(ll a){
    ll ans=0;
    ans+=(((a*(a+1)/2)%mod)*x)%mod;
    ans+=(((a/k)*((a%k)+1)%mod)*y)%mod;
        if (a/k ==0){
            return ans;
        }
    ll b=a/k-1;
    ll t=((a/k)*y)%mod;
    ans+=((((((b*(b+1)/2)%mod)*y)%mod)*k)%mod)-t;
    return ans;
    }
void solve (){
    cin>>l>>r>>x>>y>>k;
    cout<<(calc(r)-calc(l-1)+mod)%mod;
}
int main ()
{    
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen ("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int t=1;
    // cin>>t;
    while (t--)
        solve();
    return 0;
}
Copy
Practice Practice noomaL
GNU G++17
0 ms
800 KB
Wrong Answer