# Plz help me in debugging.I don't know why I am getting wrong for Chef And Ingredients Subtask-2 Task#1

#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
{
int t;
cin>>t;
while(t–)
{
long long int n,k,ans,c,b1,a2;
cin>>n>>k;
if(n==2)
{

``````        ans=(((k-1)*(k))/2);
ans=ans%MOD;
}
else
{
c=((k-1)/(n-1))+1;
if(c==1)
ans=(k-1)%MOD;
else
{
a2=((k-1)-((c-1)*(n-1)))%MOD;
b1=(((c)*((a2)+(k-1)))/2)%MOD;
ans=b1;
//cout<<c<<a2<<" "<<endl;
}

//cout<<c<<" "ans<<endl;
}
cout<<ans<<endl;
}
return 0;
``````

}

your ans is out of range,you don’t apply modulo properly,
for large value of K ,your ans in <0.

Can u please say me where to apply mod in my code .Thanks in advance !

after every +,,- apply mod,
ex,
a * b * c =mod( mod(a * b) * c)
a + b * c = mod(a + mod(b * c))
a- b * c = mod(a - mod(b
c))

for more details refer this solution,
https://www.codechef.com/viewsolution/24784367

@savaliya_vivek If you don’t mind could you please make necessary changes in my code to get A.C.