Hello mates. In the recently finished contest, regarding problem B Ela's Fitness and the Luxury Number,I submitted it using cpp 20 64-bit compiler, I got 4 WA verdicts which had cost me a lot of penalty till I solved it(pure coincidence as I tried int128 instead of ll then knew from the compiler error that type-casting is the problem so type-casted the sqrt() argument into long double and AC)
After the contest, I looked over the submissions and saw that many got it AC by cpp 17 compiler so tried my EXACT WA4 code ,but changing the compiler from cpp20 to cpp17. Magically, the same exact code was AC by cpp 17. I concluded the issue is with cpp 20's sqrt() fn, its argument should be type-casted to long double or rather use sqrtl(), but I wanna elaboration on why that happened and how not to fall in that on next contests ?? Here are my submissions: 175013082 The one Finally AC during contest after 10 tries, 175001140 WA pretest 4, 175043791 same WA4 code but AC by cpp17
UPD: It was really a well prepared contest that it rose awareness to avoid using built_in functions like sqrt() or even sqrtl() as they depend on floating pt calculation, I found this blog which is an absolute gem discussing the alternatives to those fns.
I tried implementing sqrt()fn myself using binary search returning an integer as in 175151224 and indeed got AC by cpp20 without any further type-casting avoiding any precision errors. Its complexity is logarithmic and accuracy is guaranteed.