Source Code
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
ll soso(ll n)
{
    ll sum = (n * (n + 1)) / 2;
    return sum;
}
int main()
{
ll l,r,x,y,k,sum=0;
cin>>l>>r>>x>>y>>k;
for(ll i=l;i<r+1;i++){
  if(i%k==0)sum+=i*x+i/k*y-y;
  else {
    sum+=(i-(i%k))*x+(i-(i%k))/k*y+(i%k)*x;
  }
}
cout<<sum%1000000007;
}

Copy
Practice Practice hasneen
GNU G++17
1099 ms
388 KB
Time Limit Exceeded