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

if i try to submit this code:

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)
  it is successfully accepting.....

**but if i submit any of the following codes it is partially correct....**
**#number:1**
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(int(ans))

**#number:2:**
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)

#number:3:
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)

but i don't find any difference from any of these codes as int and floor is same for positive intezers.

can any one help me with solution i wasted so much of my time to get the reason.

please help me.

the question is from june long challenge 2020,division 2,the tom and jerry game.......

**edit:** i just added indentation

Please Format your code.

Do not use floating point division if the answer is an integer.

1 Like

but i have typr casted to int in print statement right

There are a lot of threads regarding precision loss in division and the difference between / and // in Python. Take a look at those.

1 Like

it is hard to study unindented python codes.

soo sorry let me edit

1 Like

i know them but i don’t think any of them effect here

I did this

def solve():
    n=int(input())
    if n&1:
        print(n//2)
    else:
        x=math.floor(math.log(n,2))
        if 2**x==n:
            print("0")
        else:
            while not n&1:
                n=n>>1
            print(n//2)
            
    
for _ in range(int(input())):
    
    solve()

if i use floor division even i am getting right answer.

but when i use division i am getting wrong answer, i don’t know why

since ts <=10e18
so for conversion to int it cause problem


see the difference b/w a and int(a)

1 Like

but precision of ts will always be x.0 or x.5 as we are dividing it with 2

please help me


there is difference

3 Likes