Source Code
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define sz(s)    (int)(s.size())
#define endl "\n"
#define BI acos(-1)
#define all(a) a.begin(), a.end()

void Open() {
#ifndef ONLINE_JUDGE
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
#endif  !ONLINEJUDGE
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}
int dx[]{ 1, -1, 0, 0, 1, 1, -1, -1 };
int dy[]{ 0, 0, 1, -1, 1, -1, 1, -1 };
const int OO = 0x3f3f3f3f;

int main()
{
    Open();
    ll l, r, x, y, k,md=7+1e9;
    cin >> l >> r >> x >> y >> k;
    ll sum = ((r * (r + 1)) / 2 - (l * (l - 1)) / 2);
    
    ll w = r/k, ww=(l-1)/k;
    ll qe = ((r % k) ) * w ; // end
    ll qf = (((l+1) % k ) )%md * ww%md ; // first
    ll qbt =  ((w * (w - 1)) / 2)- (ww * (ww + 1)) / 2; // between
    qbt = qbt % md * k % md;
    qbt = qbt % md * y % md,qe = qe % md * y % md, qf = qf % md * y % md;
    //cout << w << ' ' << ww << ' ' << qf << ' ' << qe << ' ' << qbt << endl;
    ll ans = ((((sum % md) * x%md) % md) + (((qbt%md+qe%md) % md)+qf%md)%md) % md;
    cout << ans;

}
Copy
Practice Practice Ramy
GNU G++17
0 ms
728 KB
Wrong Answer