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.

Hey , I have checked for the square root https://codeforces.com/contest/1737/submission/175044526 it is giving AC in sqrtl and it is giving WA https://codeforces.com/contest/1737/submission/175047080 What is The difference ??

Precision issues. sqrtl() deals with the argument as long double. On the other hand, sqrt() deals with it as double, so precision is important for an accurate answer Mine worked with sqrt() in cpp20 because i type casted the argument into long double which is equivalent to using sqrtl(), the weird part is that the code with sqrt() and no type casting was

ACCnormally by cpp 17, but WA for cpp20, so it was pure luck that some people got it AC from first try and some kept getting WA4 !but I have checked p=sqrt(n) if(p*p>n) p-=1; I have found out that I am left for the case if((p+1)*(p+1)<=n) p+=1; Now I did it in this https://codeforces.com/contest/1737/submission/175050057

Yeah, I fixed the same C++20 code link

It may help you.

Yeah helped, thanks^^ Also this is an absolute gem ::

https://codeforces.com/blog/entry/107717

I tried implementing sqrt() fn myself using binary search 175151224 and indeed got AC by cpp20 without any further type casting so binary searching since we care abt integer result solved precision errors