Source Code
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
#define all(v) v.begin(), v.end()
#define pb push_back    
#define sz(x) (int)(x).size()
const int N = 3e5 + 5;
const ll M = 1e9 + 7;
inline ll add(ll a, ll b) {return a + b >= M ? a + b - M : a + b;}
inline ll sub(ll a, ll b) {return a - b <= 0 ? a - b + M : a - b;}
inline ll mul(ll a, ll b) {return (ll)a * b % M;}
// just a sec 
void solve() {
    
    ll l, r, x, y, k;
    scanf("%lld%lld%lld%lld%lld", &l, &r, &x, &y, &k);

    auto sum = [&](ll n) {
        ll ans = n * (n + 1) / 2;
        return ans;
    };

    auto solve = [&](ll a) {
        ll ans = mul(x % M, sum(a) % M);
        ans = add(ans, mul(sum(max(0ll, a / k - 1)) % M, mul(y % M, k % M)));
        ans = add(ans, mul(y % M, mul(a % k, a / k) % M));
        return ans;
    };

    ll ans = sub(solve(r), solve(l - 1));
    printf("%lld", ans);
}
int main() {
    int t = 1;
    // scanf("%d",&t);
    while(t--)
        solve();
}
Copy
Practice Practice Kamoon
GNU G++17
0 ms
744 KB
Accepted