Блог пользователя malviyanshiv

Автор malviyanshiv, история, 6 лет назад, По-английски

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 ?

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

»
6 лет назад, # |
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.

  • »
    »
    6 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    The code does work on other online compilers and also it works offline with same GCC version.

    • »
      »
      »
      6 лет назад, # ^ |
      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?

      • »
        »
        »
        »
        6 лет назад, # ^ |
          Проголосовать: нравится 0 Проголосовать: не нравится

        Yup you are right but that should not cause different results on different platform. My main problem is the cause of difference..