Created
March 26, 2015 13:02
-
-
Save jvrmaia/6ccd06751864fcc9613e to your computer and use it in GitHub Desktop.
q-matrix <3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cProfile | |
def fibonacci(n): | |
if n < 0: | |
raise ValueError("Negative arguments not implemented") | |
print _fib(n)[0] | |
def _fib(n): | |
if n == 0: | |
return (0, 1) | |
else: | |
a, b = _fib(n // 2) | |
c = a * (b * 2 - a) | |
d = a * a + b * b | |
if n % 2 == 0: | |
return (c, d) | |
else: | |
return (d, c + d) | |
cProfile.run('fibonacci(2000)') |
Author
jvrmaia
commented
Mar 26, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment