Wrong answer in test cases

#include
#include<bits/stdc++.h>
#define ll long double
using namespace std;
ll fact(ll n)
{
if((n==0)||(n==1))
return 1;

else
return n*fact(n-1);

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

}
return 0;

}

It is working fine everywhere else including coding blocks IDE.

I even unlocked the test cases to verify. And the test cases which are showing wrong answer here, are working fine when manually entered in coding blocks IDE

@a_krisna22 you have to take ll as long long int not in long double.
and you are calculating fact(p+k-1) but you cannot store factorial of large numbers in long long int so you have to come with different technique to calculate nCr.

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

Sorry mistakenly sending same code 3 time. But I tried to optimise in several. Please have a look at it. Its still not wrking

The answer will overflow 64 bits, so you need to use bigInt() here.
Take a look at its implementation here https://github.com/robinrst/HackerBlocks/blob/master/MARBLES.cpp
And here is the working code using bigInt() https://ide.codingblocks.com/s/195884

thanks I get the point, for some technical reason , nothing is happening when I submit the code. When I press submit, its just showing “submitting” for a while and then back to as if I pressed nothing.

and this is happening after I copied the entire code in the link u sent.

@a_krisna22 hard refresh your page and submit it again or submit it after some time it will work fine.