I have submitted the solution of this problem if july long challenge but it doesn't run in given time

please tell me how to optimise it further
link of my solution : CodeChef: Practical coding for everyone

code
for _ in range(int(input())):
h,p = map(int, input().split())
while h>0 and p != 0:
h = h-p
p = p/2

if p==0:
    print(0)
elif h<=0:
    print(1)

Try Pypy3, it runs faster. I myself ran it in PyPy3(your program), and it worked perfectly.

1 Like

Hey buddy!!
I have also done this problem with essentially same logic in Python 3 only.
I think you should try to define a function which does the same work as your code after reading input. I got right answer with that approach.

link to my code → CodeChef: Practical coding for everyone

1 Like

@fallmount Instead of p=p/2 , use p=p//2
In p = p/2 python automatically converts it to floating point and in case when Chef dies p will keep on decreasing but will never become zero.
eg. testcase
1
1 10
In this p=p/2 will give
p=1
p=0.5
p=0.25


1 Like

@zacros you are right. That is the only difference between my and @fallmount code.
This is the reason why my code works fine but not his.
Thanks for pointing that out.
I really need to work on my skills to point out these things.

1 Like

I tried that but it gives wrong answer @zacros, if you don’t believe you can copy my code and change normal division to floor division and submit also you can see my submission with same changes here CodeChef: Practical coding for everyone. I have also tried @anon60151173 tip and it worked just submit the same code under pypy3 and it worked here is that submission CodeChef: Practical coding for everyone. At last thanks to all

Just exchange the last if else conditions. Elif one should come first. I did so with your code CodeChef: Practical coding for everyone and it got accepted.