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 int 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;}

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 = [&](int a) {
        ll ans = mul(x, sum(a));
        ans = add(ans, mul(sum(max(0ll, a / k - 1)), mul(y, k)));
        ans = add(ans, mul(y, mul(a % k, a / k)));
        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
736 KB
Wrong Answer