#include <bits/stdc++.h>
typedef long long ll;
#define InAHurry cin.tie(0)->sync_with_stdio(0);
using namespace std;
const int M = 1e9 + 7;
ll l,r,x,y,k;
ll Solve_This_Shit(ll di) {
// int l,r,x,y,k;
ll bla =0, blabla=0, r=0;
if (di <= 1) return di * x;
r = di % k;
bla = di / k;
blabla = ((di * (di + 1) / 2)% M * x % M);
if(bla > 1) {
blabla += ((bla * (bla - 1) / 2) % M * y % M * k % M) % M; // no , never question my (fprgotten) ideas plz
}
if(bla > 0 && r > 0) {
blabla += (bla % M * r % M * y % M) % M;
}
return blabla % M;
}
int main() {
InAHurry;
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int t = 1;
//cin>>t;
while (t--) {
cin>>l>>r>>x>>y>>k;
cout<<(Solve_This_Shit(r) - Solve_This_Shit(l-1) + M) % M;
}
return 0;
}
Copy