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.
- All Contests
- ProjectEuler+
- Project Euler #145: How many reversible numbers are there below one-billion?
- Discussions
Project Euler #145: How many reversible numbers are there below one-billion?
Project Euler #145: How many reversible numbers are there below one-billion?
Sort by
recency
|
64 Discussions
|
Please Login in order to post a comment
Solved this after 3 days of analysis. Algorithm must be O(logN), otherwise it will time out. I process number digit by digit and update the count value. I created auxilarry arrays with values like: - number of reversible numbers for given number of digits and its cumulative sum - number of odd digit sums without carry over (exluding digit 0) and its cumulative sums - number of odd digit sum without carry over (including digit 0) and its cumulative sums - number of odd digits sums with carry over and its cumultaive sums - number of even digit sums without carryover and its cumulative sums
Time Out Error
For those who are struggling solving this. At one time it took me about a week of work to solve this problem, may be longer. This is no way an easy thing, and I doubt the solution can be written as one function. Particularly, my solution contains near 600 lines and 17 helper functions.
Time out can anyone fix it
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
Time Complexity :--- O(no.of test cases* n).. Suggest me ...some alternatives.. !!