akzytr's blog

By akzytr, history, 12 days ago, In English

Reffering to the 2 solutions: 259905045 and 259906344

The only difference between the codes is that one uses math.log(x) / math.log(2), and the other uses math.log2(x) for the purpose of calculating log with base 2.

The former one, using division to get the base, fails on test case. However, the output is somehow close?

Output: 4327966553 Jury: 4327967516

My first thought was that math.log(x) / math.log(2) would somehow give precision errors if the values are big enough, which seems to be the case here.

I ran a simulation though with random large numbers taken from the range 2^32 and 2^63, and calculated the log with base 2 with both. The code was supposed to break when these two differ, but this never happens.

Is it that the math.log(x) / math.log(2) gives precision errors, or not?

  • Vote: I like it
  • +14
  • Vote: I do not like it

»
12 days ago, # |
  Vote: I like it +15 Vote: I do not like it

you should just use gcc __builtin_clz instead of this imprecise log with floats and other strange stuff, it may be that it gives precision error on the server but not locally

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

    Oh yeah that makes sense. Thanks so much.