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;
}
}
}