### malviyan_shiv's blog

By malviyan_shiv, history, 12 days ago, ,

In Codeforces Round #538 (Div. 2), I submitted the solution for problem C and got WA on test case 4 ( solution link ). I checked it offline and it gave correct output for test case 4. I also checked it on online compiler ideone, and it also gave the correct result. I tried submitting in different versions of C++ ( an illogical attempt and so )... failed. Please help me to find the cause of ambiguity ?

 » 12 days ago, # | ← Rev. 2 →   +5 I tried several changes, and come up with that the bug is in log2(n)/log2(b) (and also the one below it in the code) and when n = b, then the result of the division will be something like 0.99999... which will be 0 after casting to long long. So, you should use floor() or ceil() according to what you want.
•  » » 12 days ago, # ^ |   0 The code does work on other online compilers and also it works offline with same GCC version.
•  » » » 11 days ago, # ^ | ← Rev. 3 →   +5 Yeah, but in these cases, we should take the worse behaviour. We should know that double may lose precision while processing it with integer types, so why to not be careful while using it?
•  » » » » 11 days ago, # ^ |   0 Yup you are right but that should not cause different results on different platform. My main problem is the cause of difference..