Getting all test cases wrong except one

I am getting all the test cases wrong except one.
Please help me to debug my code.
https://ide.codingblocks.com/s/72227

hi

Can you tell your the mathematical ans that you derived ??

it’s just a mathematical question of PnC
tell me if you able to get that,

Thes, I did C(N-1,K-1), because we have n marbles and we will give k marbles and then we will apply PnC

your equation is correct you just have to use small optimisation

see here

    if( n-k < (k-1))//Its IMPORTANT! to get accepted
    k=n-k+1;//selecting the smaller value
    if(k==1)
    printf("1\n");
    else
    {
         for(i=1;i<=k-1;i++)
        {
        res=res*(n-i)/(i); 
   /* Dont do res*((n-i)/(i));divide then multiply
    * but instead do res*(n-i)/(i); Its multiply and divide */
        }
     }

I did this only, But I am still getting wrong output.

if( (n.subtract(k)).compareTo(k.subtract(BigInteger.ONE))<0)
k=(n.subtract(k)).add(BigInteger.ONE);
if(k==BigInteger.ONE)
System.out.println(1);
else{
BigInteger res = BigInteger.ONE;
for(BigInteger i =BigInteger.ONE;i.compareTo(k.subtract(BigInteger.ONE))<=0;i=i.add(BigInteger.ONE)){
res = (res.multiply((n.subtract(i))).divide(i));
}
System.out.println(res);
}

I am getting correct answer for every C(N-1,K-1)

check for
test case
1
64 30

yes your code is correct, try doing the code without using big integer class in java

759510004936100355 I am getting this

Did without bigInteger class too…But same results

can you share link of that code without bigInteger Class

This is wrong i guess

https://ide.codingblocks.com/s/72980 this is the code without any consideration of time complexity

hi
shayd kuch compiler issue i have asked the team to look into it, coz only java code is giving wrong ans and your code is accepted on spoj

ooo…Thank you so much.

Hi
the test cases are now updated and you can submit your solution, your code works fine!
there was issue with the test cases.

Hit like if you get it!
Cheers!

1 Like

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.