Solution not getting judged

#include
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
ll comb(ll n, ll r)
{ ll i,p,q,m,x,y;
ll res=1;
for(i=1;i<=r;i++)
{ p=n-i+1;q=i;
m=__gcd(p,q);
x=p/m;
y=q/m;
res=res*x;
res=res/y;
}
return res;
}

int main() {
ll t;
cin>>t;
while(t–)
{
ll n,k,p,res,x,y;
cin>>n>>k;
p=n-k;
x=p+k-1;
y=k-1;
if(y>x/2)
{
y=x-y;
}
res=comb(x,y);
cout<<res<<endl;

}
return 0;

}

This question is directly taken from SPOJ . My solution is getting accepted there in SPOJ finally after a lot of optimisations, But my code is still not working here. Sometimes it shows “session not judged”, or simply wrong answer in 4 out of 5 test cases. Cant really figure it out.

@a_krisna22 I think it’s somewhat wrong.
Take x=n+k-1 and y=k-1. It would work.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.