MARBLES couldnt pass all the test case despite correct logic

I am trying to solve this problem but couldnt get pass all of them what might be the reason

#include<bits/stdc++.h> #define ll long long int using namespace std; ll foo(int n, int k){ if(k > n - k) k = n - k; int res = 1; for(int i = 0; i < k; i++){ res *= (n - i); res /= (i + 1); } return res; } int main(){ int t; cin>>t; while(t–){ ll a, b; cin>>a>>b; cout<<foo(a - 1, b - 1)<<"\n"; } return 0; }

for same problem my solution got accepted on codechef why aint here

hey @FAYAZ The answer is overflowing 64 bits, so you need to use an implementation of big int class.
Also while calculating result ,you are assuming that res will always be divisible by (i+1),which is not true.
Try to use the formula (N+R-1) C (R-1) and calculate the numerator and denominator separately.
Here take a look at this implementation https://ide.codingblocks.com/s/175007, this uses bigint() to avoid overflow.