# fibfact.py: succ fib #'s and factors
import sys
import math # for sqrt
def bound(k): # best bound
return int(math.sqrt(k))
def fib_fact(m):
f = 1 # F(2)
g = 2 # F(3)
n = 3 # index of fib #, init 3
while m - n: # keep going through m fib #s
sys.stdout.write(str(n) + "\t" + str(g) + "\t")
j = g # init g = F(3), then iter through fib #s
# based on value of g, set x so that x*x > g,
# or, x > sqrt(g). Only check factors up to x
x = bound(j)
d = 2 # initial trial divisor, after mults by 2,
# will switch to 3, then use 3, 5, 7, 9, etc
t = 1 # means d is a trial divisor
while t:
if j % d:
e = 0
else:
e = 1
while e: # d is a divisor, divide it out
j = j/d
# did a division, recalculate magic x
x = bound(j)
sys.stdout.write(str(d) + ' ')
if j% d:
e = 0
else:
e = 1
if j - 1: # keep going until j is 1
t = 1
else:
t = 0
if d - 2:
if d < x: # inside bound
d = d + 2
else:
d = j # terminate
else:
d = 3
# if d is 2, change d to 3, else incr d by 2
# eventually d == j, so d divides into j,
# and will have last factor.
# j == 1 will set t == 0, which terms while
# above also checks for bound. d = j termis
sys.stdout.write("\n")
n = n + 1 # next index
h = f + g # next fib number
f = g # adjusting previous fib #s
g = h # ditto
m = raw_input( "-->" )
fib_fact(int(m))
|
3 2 2
4 3 3
5 5 5
6 8 2 2 2
7 13 13
8 21 3 7
9 34 2 17
10 55 5 11
11 89 89
12 144 2 2 2 2 3 3
13 233 233
14 377 13 29
15 610 2 5 61
16 987 3 7 47
17 1597 1597
18 2584 2 2 2 17 19
19 4181 37 113
20 6765 3 5 11 41
21 10946 2 13 421
22 17711 89 199
23 28657 28657
24 46368 2 2 2 2 2 3 3 7 23
25 75025 5 5 3001
26 121393 233 521
27 196418 2 17 53 109
28 317811 3 13 29 281
29 514229 514229
30 832040 2 2 2 5 11 31 61
31 1346269 557 2417
32 2178309 3 7 47 2207
33 3524578 2 89 19801
34 5702887 1597 3571
35 9227465 5 13 141961
36 14930352 2 2 2 2 3 3 3 17 19 107
37 24157817 73 149 2221
38 39088169 37 113 9349
39 63245986 2 233 135721
40 102334155 3 5 7 11 41 2161
41 165580141 2789 59369
42 267914296 2 2 2 13 29 211 421
43 433494437 433494437
44 701408733 3 43 89 199 307
45 1134903170 2 5 17 61 109441
46 1836311903 139 461 28657
47 2971215073 2971215073
48 4807526976 2 2 2 2 2 2 3 3 7 23 47 1103
49 7778742049 13 97 6168709
50 12586269025 5 5 11 101 151 3001
51 20365011074 2 1597 6376021
52 32951280099 3 233 521 90481
53 53316291173 953 55945741
54 86267571272 2 2 2 17 19 53 109 5779
55 139583862445 5 89 661 474541
56 225851433717 3 7 7 13 29 281 14503
57 365435296162 2 37 113 797 54833
58 591286729879 59 19489 514229
59 956722026041 353 2710260697 |