Doubt in test cases

I am not able to figure out what is wrong in my code, even the code in an editorial in not passing all cases

#include <bits/stdc++.h>
using namespace std;

long long int ncr(int n,int r){
long long int ans=1;
int a=max(r,n-r);
for(int i=n;i>a;iā€“){
ans*=i;
ans/=(n-i+1);
}
return ans;
}

int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);

int t;	cin>>t;
while(t--){
    // your code goes here
	int n,k;cin>>n>>k;
	cout<<ncr(n-1,k-1)<<endl;
}
return 0;

}


Here is the code by @sdevwrat