thedsk's blog

By thedsk, history, 7 years ago, In English

I have been trying this question and i am getting wrong answer on testcase2.I m using codechef compiler right now and it is printing the expected output.But codeforces is giving me wrong answer and I dont know why.Link to my code is below and i have tried to submit this solution in two different languages GNUC++ and GNUC++11. If I increment x by 1 it fails test case 3.Can u plz help!!! http://codeforces.com/contest/808/submission/28206449

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

| Write comment?
»
7 years ago, # |
  Vote: I like it 0 Vote: I do not like it

The function pow in C++ is only defined for floating point numbers. So pow(10, 2) might return 99.99999999999 instead of 100 (e.g. when performed on a different compiler / different architecture) and then get truncated to 99 when you convert it to an int. If you want to perform integer exponentiation, always write a pow function yourself.

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

I also had problem with pow in this problem at the contest, so I changed it to my own binary power function, it worked. Don't use pow, it is slow and it have problems with long long.

Here is your fixed submission: http://codeforces.com/contest/808/submission/28207320