In the recent contest Educational Codeforces Round 147 (Rated for Div. 2), Question C. I faced ambiguity when compiling my code with GNU G++17 7.3.0. Here is my submitted code 202889532 and 202887839
When line 35, which is an output statement, is commented out. I get different return value
If I print an empty string "", my return value, and hence output changes.
Please have a look! MikeMirzayanov
It's NEVER the compiler's fault.
there are some extremely rare documented exceptions to this general rule
Can you help me troubleshoot the problem?
It could be a double precision error. Try calculating $$$\log_2 x$$$ using integers only. In your example $$$m = 8$$$, so my guess is, that $$$log_2 8$$$ will be something like $$$2.9999 \ldots$$$, instead of $$$3$$$, and it gets rounded down to $$$2$$$.
Seems to be a case of excess precision. The difference between the two cases might be that the call to
cout
can fail (or have some other side-effect) that forces the compiler to not optimize away the store tot
.However this still doesn't guarantee that your code will AC — even if the underlying logic is correct, the division of the logs seems quite unreliable.