i need to apply modulus e=10^9+7 on the given expression i*(n+k-2)-((i*(i+1)*(n-1))/2) where i is in terms of n and k . n and k are inputted by the user. 2≤N≤10^18 1≤K≤10^18
i tried using modular arithmetic using the basics i.e (a-b)%e=((a%e)-(b%e))%e and (ab)%e=((a%e)(b%e))%e.
//i have taken unsigned long long int as the data type for all variables
a=1;
b=1;
cin>>n>>k;
i=(n+k-2)/(n-1);
//s=(i*(n+k-2))-((i*(n-1)*(i+1))/2
j=(i+1);
p=n+k-2;
q=n-1;
r=i/2;
u=j/2;
if(i%2==0)
{
a=(a*i)%e;
a=(a*p)%e;
b=(b*r)%e;
b=(b*q)%e;
b=(b*j)%e;
s=a-b;
}
else
{
a=(a*i)%e;
a=(a*p)%e;
b=(b*u)%e;
b=(b*q)%e;
b=(b*i)%e;
s=a-b;
}
cout<<s%e<<endl;
i am getting correct answers for small test cases but for large test cases i am not getting the correct answer.