Pisano periods and Fibonacci

300 days ago by cannongerald

def verify_FibPis(n): N = n a = mod(1, 10^20) A = matrix(2,2,[a,a,a,0]) M = matrix (2,2,[a,0,0,a]) while N>0: if is_odd(N): M = A*M N = (N-1)/2 else: N= N/2 A = A * A print(M[0][1]) #prints the first row and second column return(M[0][0]) #returns the first row and first column 
       
M = 15*10^19 CUID = 13638361 verify_FibPis(M) 
       
0
1
0
1
verify_FibPis(M/2) 
       
0
50000000000000000001
0
50000000000000000001
verify_FibPis(M/3) 
       
40816211700439453125
32023715972900390626
40816211700439453125
32023715972900390626
verify_FibPis(M / 5) 
       
60000000000000000000
80000000000000000001
60000000000000000000
80000000000000000001
def Fib_Pis(n,m): N = n pisanoper = 15*10^(m-1) N = N % pisanoper # divides m by the pisanoper that will have a remainder of 0 a = mod(1, 10^20) A = matrix(2,2,[a,a,a,0]) M = matrix (2,2,[a,0,0,a]) while N>0: #loop that lets the IDE know to keep going until m is smaller then n, and not able to keep going if is_odd(N): M = A*M N = (N-1)/2 else: N= N/2 A = A * A #sets up the identity matrix return(M[0][1]) #returns the first row and second column 
       
t = cputime() print(Fib_Pis(P,20)) print(cputime()-t) #prints the time it requires the program has run 
       
Traceback (click to the left of this block for traceback)
...
NameError: name 'P' is not defined
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "_sage_input_15.py", line 10, in <module>
    exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("dCA9IGNwdXRpbWUoKQpwcmludChGaWJfUGlzKFAsMjApKQpwcmludChjcHV0aW1lKCktdCkgI3ByaW50cyB0aGUgdGltZSBpdCByZXF1aXJlcyB0aGUgcHJvZ3JhbSBoYXMgcnVu"),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
  File "", line 1, in <module>
    
  File "/tmp/tmp_zVb_9/___code___.py", line 4, in <module>
    print(Fib_Pis(P,_sage_const_20 ))
NameError: name 'P' is not defined