xeronix's blog

By xeronix, 12 years ago, In English

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 ?

  • Vote: I like it
  • 0
  • Vote: I do not like it

»
12 years ago, # |
  Vote: I like it +1 Vote: I do not like it

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 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    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.