0 0 |
1 1 |
How can we compute the first 10 fibonacci numbers (badly)?
1 1 |
2 2 |
3 3 |
5 5 |
8 8 |
13 13 |
21 21 |
|
34 34 |
55 55 |
Clearly the wrong way to do things!
|
354224848179261915075 354224848179261915075 |
354224848179261915075 354224848179261915075 |
Next modification: Start with n=desired index to compute
354224848179261915075 354224848179261915075 |
Now let's define a function myfib(n) which will return the nth fibonacci number
|
Traceback (click to the left of this block for traceback) ... __SAGE__ ^CTraceback (most recent call last): File "<stdin>", line 1, in <module> File "_sage_input_36.py", line 10, in <module> exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("bGVuKG15ZmliKDEwMDAwMDAwKS5kaWdpdHMoKSk="),globals())+"\\n"); execfile(os.path.abspath("___code___.py")) File "", line 1, in <module> File "/tmp/tmpgFfIll/___code___.py", line 3, in <module> exec compile(u'len(myfib(_sage_const_10000000 ).digits()) File "", line 1, in <module> File "/tmp/tmp3AecZU/___code___.py", line 8, in myfib next_value=current_value+previous_value # Compute the next Fibonacci number File "sage/ext/interrupt/interrupt.pyx", line 203, in sage.ext.interrupt.interrupt.sage_python_check_interrupt (/usr/local/sage-6.10/src/build/cythonized/sage/ext/interrupt/interrupt.c:1891) File "sage/ext/interrupt/interrupt.pyx", line 88, in sage.ext.interrupt.interrupt.sig_raise_exception (/usr/local/sage-6.10/src/build/cythonized/sage/ext/interrupt/interrupt.c:925) KeyboardInterrupt __SAGE__ |
2089877 2089877 |
6942418 6942418 |
F($10^7$) has around 2 million digits: too many to handle! Let's instead just ask for the final ten digits.
So, do our computations modulo $10^{10}$.
|
9261915075 9261915075 |
8242546875 8242546875 |
6380546875 6380546875 |
|
|