Birthday_paradox problem

On solving this problem on hacker blocks by this method the 2 test case always goes wrong. Why?
https://hack.codingblocks.com/contests/c/126/827

which method?
secondly watch out for n=1.