Problem code:EOEO ,problem name: The Tom and Jerry Game!

can any one tell me why i am getting partially correct with this

# cook your dish here
t=int(input())
for i in range(t):
    ans=0
    ts=int(input())
    while(ts%2==0):
        ts=ts/2
    ts=int(ts)
    if ts%2!=0:
        ans=ts//2
    print(ans)

while i am getting correct answer for all the test cases for the following code:(we have to get the same answer with floor divison normal divison for even numbers rightt)

# cook your dish here
t=int(input())
for i in range(t):
    ans=0
    ts=int(input())
    while(ts%2==0):
        ts=ts//2
    if ts%2!=0:
        ans=ts//2
    print(ans)

can any one please help me…

ts can never be 5. as ts is always even.

and even with int(ts/2) is giving wrong

please try to help

please look at the code .i changed it as you said ,but still it is giving wrong answer for private test cases

please look at my reply

Did a little change- AC Code
What you did wrong, was ts=ts/2 returns x.0. So just do ts//2

This should be ts = ts//2 for right answer.
Check this thread. It explains clearly why ts = ts/2; ts = int(ts) will fail. There will be some precision loss when you are dealing with floating point values.

1 Like