Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python2
- import DecInt
- donecount = 0
- gcache = dict()
- gcache[0] = DecInt.DecInt(0)
- gcache[1] = DecInt.DecInt(1)
- def g(x):
- if x not in gcache:
- gcache[x] = (g(x-1)+g(x-2)).square()
- global donecount
- donecount += 1
- print donecount
- return gcache[x]
- wcache = dict()
- wcache[0] = DecInt.DecInt(0)
- wcache[1] = DecInt.DecInt(1)
- def w(x):
- if x not in wcache:
- wcache[x] = (w(x-1)).square() + (w(x-2)).square()
- global donecount
- donecount += 1
- print donecount
- return wcache[x]
- def f(x):
- global donecount
- result = g(x)-w(x)
- donecount += 1
- print donecount, 'f(%d) done' % x
- return result
- def sumdigits(n):
- return sum(map(int, repr(n)[8:-2]))
- sdigits = 0
- while n:
- n, d = divmod(n, 10)
- sdigits += d
- return sdigits
- print sumdigits(f(30))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement