Source Code
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll mod = 1000000007;
ll Sum(ll n) {
    return n*(n+1)/2;
}
ll l,r,x,y,k;
ll Get(ll n) {
    ll cnt = n/k;
    ll ret = Sum(cnt)%mod;
    ret *= k;
    ret%=mod;
    ret += (n%k)*(cnt+1);
    ret%=mod;
    return (ret - n+mod)%mod;
}
int main(){
    ios_base::sync_with_stdio(0);
    cin>>l>>r>>x>>y>>k;
    ll breaks = (Get(r) - Get(l-1)+mod)%mod;
    ll ret = (breaks*y)%mod + (((Sum(r)-Sum(l-1))%mod)*x)%mod;
    ret%=mod;
    cout<<ret<<endl;
}

Copy
Practice Practice RedNextCentury
GNU G++17
0 ms
748 KB
Accepted