Some doubts in solving LogiCode problems

LOGIC1 Problem:

For this problem, I thought strategy of binary search would work. By every one experiment we can eliminate half of the possiblities and ceil(log(n))+1 would be the answer. I was getting wrong answer.
After completion of contest, when I saw others’ code, I found that most of people were using following strategy:

  1. ans = sqrt(2n)

  2. if(ans * (ans + 1) < n )

Can somebody tell me how it works ?

LOGIC2 Problem:

For this problem, I figured out strategy in last 2 minutes. Due to lack of time I could not code the solution. But if i have coded it it could have got WA. Strategy I was thinking was that

Get prime factorization of numbers. If number of prime number is even then CODY will even, otherwise ZACH will win.

Can somebody tell me what is wrong with this?

For LOGIC1, check out
This website gives a very nice explanation for the case N=100 (which itself is a classic interview question). There, different strategies are explored and finally, the optimal solution.

1 Like

Thanks tijo. Explanation and website is really helpful.

1 Like