Same code works on C++ but not in python

@sachin_01 For very large number int() isn’t that accurate.
E.g.-
print(99997777555533331//2) >>> 49998888777766665
print(int(99997777555533331/2)) >>> 49998888777766664

1 Like

@rahul u r right it happens because when we use / the result is calculated in floating point ,and internally it is stored in hardware optimised IEEE-754 binary64 standard.
/ will give you wrong answer for even smaller inputs further when u use int over it ,it may results in wrong/unexpected answer .
for ex. 10/3
print(int(1.9999999999999999999)) will return 2 instead its floor value that is 1
thats why i use and recommend using // if u want floor value.
if anyone wants complete explanation of IEEE–754 binary64 standard.
plz let me know
@sachin_01 @sid_121212

1 Like

Precision error for 10**18 in dividing

you can use

from decimal import Decimal
print( int( Decimal(ts)  /  Decimal(2) ))

this will work

i used floor only ,check my solution , after that also it was showing partially correct then i submitted the same solution in cpp it worked .
Btw thanks :blush: @faisal1947

1 Like

u r welcome buddy.

try using “//” in line 12 of your solution, it shall work, or have a look at my solution for this question.

Happened to my python code too I tried with floor operator and int type conversion both. Eventually after 5 partially accepted submissions, submitted the code in C++ got 100!