Pavel's blog

By Pavel, history, 11 days ago, In English,

Why I am getting different output? Someone please explain the reason behind the WA. Ideoned code: https://ideone.com/ZjNybK CF Submission: https://codeforces.com/contest/1114/submission/49755099

 
 
 
 

»
11 days ago, # |
  Vote: I like it +1 Vote: I do not like it

LONG_MAX is basically 2147483647. So, the answer can be greater than 2147483647. That's it is giving Wrong Answer. Use LLONG_MAX instead.

»
11 days ago, # |
  Vote: I like it 0 Vote: I do not like it

Brother, my soln too got a wa https://codeforces.com/contest/1114/submission/49716174 Can anyone explain why?

  • »
    »
    11 days ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    https://ideone.com/jfyHLZ This is Your AC solution. The problem was due to over flow when you multiply e = e * x.f Instead if u check if e <= n / x.f it will work finely. I was also unable to find this during the contest.

    • »
      »
      »
      11 days ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Yeah it got too late to realise that. Thanks by the way!

»
11 days ago, # |
Rev. 2   Vote: I like it +1 Vote: I do not like it

Overflow in this line " for(long long i=mp;n/i>=1;i = i*mp) "

For example: i = mp = 100000015333 and n = 1e12, n still larger than i but i * i will be overflowed

  • »
    »
    11 days ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Where will I set the condition? I am confused :|