Skip to content

Instantly share code, notes, and snippets.

@ebartrum
Last active August 29, 2015 14:12
Show Gist options
  • Save ebartrum/cba4fe5cebec90f85380 to your computer and use it in GitHub Desktop.
Save ebartrum/cba4fe5cebec90f85380 to your computer and use it in GitHub Desktop.
463 in progress
#Define the function f by recursion:
def f(n):
if n==1:
return 1
if n==3:
return 3
if n%2==0:
return f(n/2)
if (n-1)%4==0:
m=(n-1)/4
return 2*f(2*m+1)-f(m)
if (n-3)%4==0:
m=(n-3)/4
return 3*f(2*m+1)-2*f(m)
def s(n):
ans=0
for m in xrange(1,n+1):
ans+=f(m)
return ans
print s(3**37)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment