the only think where i think it can go wrong is I am using type casting in python but as far as i know it should convert 5.4 or 5.99 also to 5 hence should give similar result to the c++ code
Use //
instead of int()
1 Like
Fixed it. Avoid int()
.
t=int(input())
for i in range(t):
tom=int(input())
ans=0
if(tom%2!=0):
ans=tom//2
else:
div=1
otom=tom
while tom%2==0:
tom=tom//2
div=div*2
div=div*2
ans=otom//div
print(ans)
Just made slight modifications to your code.
// gives you GREATEST INTEGER FUNCTION or whatever (int part of the quotient)
So use a//b instead of int(a/b)
yes…exactly
thanks you I got your point but i am still not getting why int(tom/2) is not equavilent to tom//2