CHFING Python Syntax problem Help

I just want to know,
Why int(a/b) or math.floor(a/b) is not working instead of a//b in this question or in general? What are the cases where using first 2 methods will give different results than a//b?

My solutions links where i have used following methods to code :

  1. int(a/b) : https://www.codechef.com/viewsolution/24866057
  2. math.floor(a/b) : https://www.codechef.com/viewsolution/24866078
  3. a//b : https://www.codechef.com/viewsolution/24866054

Only 3rd one is AC.

I have read this stackoverflow post but it doesn’t explain case of both positive numers : https://stackoverflow.com/questions/12843750/integer-division-is-a-b-inta-b-true-for-all-integers-a-b

int(a/b) first calculates a/b which is a floating point number in python3.6 ( and they have precision issues ) and then converts it into an integer. Similar thing with math.floor(a/b).
1 2 more in depth

1 Like

You lost some precision, when you convert float into int.

1 Like