My issue
how can i solve this using recursion in python
need the test case to which it is returning “runtime limit exceeded”
My code
# cook your dish here
def prime(n):
if n == (0 or 1):
return False
for i in range(2,n//2):
if n%i == 0:
return False
return True
def defeat(h,i,c):
if h < 0:
return -1
if h == 0 or prime(h):
c += 1
return c
else:
return defeat(h-i,i*2,c+1)
for _ in range(int(input())):
h = int(input())
print(defeat(h, 1, 0))
Problem Link: Monsters Practice Coding Problem - CodeChef