We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.

Facing timeout problem... !!
def procedure(n):
s=str(n)
#print("s = ",s)
s1 = s[::-1]
if int(s1)>10:
#print("s1 = ",s1)
#print(int(s1))
s2=n+int(s1)
#print("s2 = ",s2)
if '2' not in str(s2) and '4' not in str(s2) and'6' not in str(s2) and'8' not in str(s2) and'0' not in str(s2):
return True
else:
return False

t=int(input())#no of test cases
while t>0:
n=int(input())
c=0
for i in range(10,n):
if procedure(i)==True:
c=c+1

print(c)
t=t-1

Time Complexity :--- O(no.of test cases* n).. Suggest me ...some alternatives.. !!

## Project Euler #145: How many reversible numbers are there below one-billion?

You are viewing a single comment's thread. Return to all comments →

Facing timeout problem... !! def procedure(n): s=str(n) #print("s = ",s) s1 = s[::-1] if int(s1)>10: #print("s1 = ",s1) #print(int(s1)) s2=n+int(s1) #print("s2 = ",s2) if '2' not in str(s2) and '4' not in str(s2) and'6' not in str(s2) and'8' not in str(s2) and'0' not in str(s2): return True else: return Falset=int(input())#no of test cases while t>0: n=int(input()) c=0 for i in range(10,n): if procedure(i)==True: c=c+1

Time Complexity :--- O(no.of test cases* n).. Suggest me ...some alternatives.. !!