Why getting WA in Chef and Walk

Problem link : CodeChef: Practical coding for everyone

my solution link : CodeChef: Practical coding for everyone

I have first calculated the first occurrence of n by formulae (n+1)^2 - n+1 and then accordingly calculated the remaining walks somebody please help me out !

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll M = 1000000007;

int main()
{
int t;
cin>>t;
while(t–)
{
ll n,k,first,a; cin>>a>>k;
if(k%2)
{
n=(a+1+(k-1)/2);
cout<<(n * n-n-a)%M<<endl;
}
else
{
n=(a+1+(k-2)/2);
cout<<(n * n-n+a)%M<<endl;
}
}
}

your accepted solution.

you missed the case of 0

1
0 3

1 Like

The link you’ve provided is to the submission page, not your submission :confused:

https://www.codechef.com/viewsolution/32385968

1 Like

i thought it is handled with the same conditions
btw Thanks a lot :slight_smile: