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.
Since Python has a longer timeout, tried to implement the same thing in Python. No dice. Can someone point me in the right direction?
#f(0) = 0#f(1) = 1#f(2n) = f(n) , for all even numbers#f(2n+1) = f(n) + f(n+1) , for all odd numbersdeffn(n):if(n==0)or(n==1):returnn;elif(n%2==0):#evenreturnfn(n/2);elif(n%2==1):#oddreturnfn((n-1)/2)+fn((n+1)/2);return-1num=int(input())print(int(fn(num+1)))
Project Euler #169: Exploring the number of different ways a number can be expressed as a sum of powers of 2.
You are viewing a single comment's thread. Return to all comments →
Since Python has a longer timeout, tried to implement the same thing in Python. No dice. Can someone point me in the right direction?