Can anyone tell me why the first solution gives TLE while second one passes …
The only difference is that i have used long double instead of double in second solution…
is this unexpected or long double is faster than double
@ssrivastava990
@aneee004
@ssjgz
https://www.codechef.com/viewsolution/37289421
Bro I think in double it will overflow , may be.
but double has a range same as long double
refer this documentation
No idea buddy then , wait if I m using upper bound to 1010 my code gives TLE.
i have used 1e10 in both codes other one passed well under time!
Imagine a situation when
l = 10^{10}-10
r = 10^{10}
(l + r) would overflow
but this article says something different about range of double and long double
In our first year we learn that datatype ranges are compiler dependent. So try running this code on codechef compiler
also the biggest datatype on most OJs is a long long
and long long can’t store something like 10^{20} so it’s obvious long double can’t do it as well
When we take about the range of values… they may be same. Although this depends on the compiler… But regarding precision… it is probable, that double does not act synonymous to long double.
Refer to this article for better understanding:
https://stackoverflow.com/questions/14221612/difference-between-long-double-and-double-in-c-and-c#:~:text=The%20type%20double%20provides%20at,of%20the%20type%20long%20double.
so can you tell me exactly what would be the integer range of double and long double