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

Автор xeronix, 12 лет назад, По-английски

Here is my code for the problem : http://ideone.com/UHbff

I got WA because on Codeforces judge for input 1 10000, its giving 10007 but on ideone and my system it gives 10008. Am i using any compiler version dependent statement ?

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

»
12 лет назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

It's because of using the pow function. It returns double/float and in some versions (for example, MinGW) it can result in something like 999999.999999 instead of 1000000 which is rounded to 999999.

Never use such floating point functions when you need to work with integers. You never know what it'll return. You'd better to write your own function powll which works with long longs

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

    Ahh, i knew beforehand that pow might cause problem and i tested on MinGW-g++(windows) + g++(Linux) on several test cases before submission( indeed i shouldn't have relied on those test cases output ). I think apart from compiler its somewhat system dependent also.