#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mp make_pair
#define pb push_back
#define lp(i,s,f) for(ll i = s; i < ll(f); i++)
#define inF freopen("input.in", "r", stdin);
#define outF freopen("output.in", "w", stdout);
#define endl '\n'
#define MOD 1000000007
#define mm(arr) memset(arr, 0, sizeof(arr))
#define F first
#define S second
#define int ll
int x, y, k;
int F(int n){
if(n == 0){
return 0;
}
int ans = ((n * (n + 1)/2)%MOD * x)%MOD;
int takeOut = ((n/k) * y)%MOD;
//(n/k) + (n - 1)/k + (n - 2)/k + ... + 2/k + 1/k * y
ans += ((n/k * (n%k + 1))%MOD * y)%MOD;
ans %= MOD;
n = n/k * k;
n--;
if(n == -1){
return ans;
}
int num = n/k;
ans += ((((num * (num + 1)/2)%MOD)*k)%MOD * y)%MOD;
ans %= MOD;
ans -= takeOut;
ans += MOD;
ans %= MOD;
return ans;
}
int32_t main(){
FAST
int l, r;
cin >> l >> r >> x >> y >> k;
cout << (F(r) - F(l - 1) + MOD)%MOD;
return 0;
}
Copy