0 0 |
1 1 |
55 55 |
Let's write some bad code and see if we can test how many recursive calls it makes.
|
|
128013529779468136153585136825101961538900481122065445964837651183086898\ 754026550517136497483483470641608626276464055059332628575928521597999901\ 718592957423352363167465917636140408184822379391543598931815814725878528\ 845711814356562816020703656120345663431005792446926782064141406206872674\ 044496382612109555705276756054608939403080010257497520565825039141232590\ 185236536300243432404427078483449695275223922784635210975743019657462141\ 365577883788628334421325013343898945369582265133225052581547429120787483\ 968895443714869214153983484196368957200111230649716136282989616442150717\ 747827588840460128198812637224475960962985001698982034192388374058622072\ 865322851268191822192497641904232912275607663029887240803055414422300714\ 028137340125 128013529779468136153585136825101961538900481122065445964837651183086898754026550517136497483483470641608626276464055059332628575928521597999901718592957423352363167465917636140408184822379391543598931815814725878528845711814356562816020703656120345663431005792446926782064141406206872674044496382612109555705276756054608939403080010257497520565825039141232590185236536300243432404427078483449695275223922784635210975743019657462141365577883788628334421325013343898945369582265133225052581547429120787483968895443714869214153983484196368957200111230649716136282989616442150717747827588840460128198812637224475960962985001698982034192388374058622072865322851268191822192497641904232912275607663029887240803055414422300714028137340125 |
Let's write a bottom up function to compute F(n)
|
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_45.py", line 10, in <module> exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("bGVuKG15X2ZpYl9iZXR0ZXIoNDAwMDAwMCkuZGlnaXRzKCkp"),globals())+"\\n"); execfile(os.path.abspath("___code___.py")) File "", line 1, in <module> File "/tmp/tmpGn0lxW/___code___.py", line 3, in <module> exec compile(u'len(my_fib_better(_sage_const_4000000 ).digits()) File "", line 1, in <module> File "/tmp/tmp6d3lKp/___code___.py", line 15, in my_fib_better c=a+b # add the previous two fibonacci numbers 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__ |
Clearly the second program works better than the first. But keeping all the digits is messing things up. Let's just keep 20 digits.
|
20015045536383715033346875 20015045536383715033346875 |
200098789059742454288546875 200098789059742454288546875 |
This works better for computing the final 20 digits of F(n)!
Your individual $n$ is going to be $n=7^k$ where $k$ is your 8 digit CUID.
Your assignment is to compute the final 20 digits of $F_n$.
117= 64+32+16+4+1
|
|
<type 'sage.rings.finite_rings.integer_mod.IntegerMod_gmp'> <type 'sage.rings.finite_rings.integer_mod.IntegerMod_gmp'> |
<type 'sage.rings.integer.Integer'> <type 'sage.rings.integer.Integer'> |
|
|
|
|
|
[1, 0, 1, 0, 1, 1, 1] [1, 0, 1, 0, 1, 1, 1] |
280735493 280735493 |
When raising numbers to a high power, things get very big very quickly!
When raising matrices to a high power, the same thing happens.
So we really do need to control the size of the results e.g. by taking things (mod n).
|
Can we explore other ways of doing things? Let's think about arithmetic modulo n.
|
|
|
It appears that the sequence of powers of 17 (mod 46) repeats.
Why?
|
|
|
|