Source Code
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define AiBak_is_Here main
int AiBak_is_Here()
{
    ll l,r,x,y,k,sum=0,sum1=0,mi=0,c=0,value=0;
    cin>>l>>r>>x>>y>>k;
    sum=r*(r+1)/2-(l-1)*l/2;
    if(k>1){


    for(ll i=k;i<=r;i+=k)
    {
        c++;
        if(i>=l && i<=r  )
        {
            if(i+k<=r)
            {
            value+=k*c*y;
            }
            else
            {
                value+=(r-i+1)*c*y;
            }
            mi++;
        }
        else
        {
            if(i+k>l && i+k<r)
            {
                value+=(i+k-l)*c*y;
            }
        }
    }
     mi*=y;
    sum1+=value+sum*x-mi;
    }
    else
    {
        sum1+=sum%(1000000000+7)*x;
        sum1+= sum%(1000000000+7)*y;
        sum1-=(r-l+1)*y;

    }

    cout<<sum1%((1000000000+7));


}
Copy
Practice Practice ai365ak
GNU G++17
103 ms
616 KB
Wrong Answer