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

using namespace std;

#define all(x) (x).begin(), (x).end()
#define fast ios::sync_with_stdio(false);cin.tie(0);
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int mod = 1e9 + 7;

int main(){
	fast
	ll l,r,x,y,k;
	cin>>l>>r>>x>>y>>k;

	// ll ans2 = 0;
	// for(int i=l;i<=r;i++){
	// 	ans2 += i * x;
	// 	ans2 += (ll)((i-1)/k) * y;
	// }
	// cout << ans2 << '\n';

	ll ans = (r-l+1) * (l+r) / 2;
	ans %= mod;
	ans *= x;
	ans %= mod;
	ll fr = (l + k - 1)/k;
	ll to = r / k;
	fr--;
	to--;
	if(fr != to){
		ll cur = (to - fr + 1) * (to + fr)/2;
		cur %= mod;
		cur *= k;
		cur %= mod;
		cur *= y;
		cur %= mod;
		ans += cur;
		ans %= mod;
	}
	fr++;
		
	if(l % k != 1){
		ans += ((((k*fr) - l + 1) * (fr - 1))%mod)*y;
		ans %= mod;
	}

	if(r % k != 0){
		ans += (((r - (k*(to+1)+1) + 1) * (to+1))%mod)*y;
		ans %= mod;
	}

	cout << ans << '\n';

}
Copy
Practice Practice Warawreh
GNU G++17
0 ms
608 KB
Wrong Answer