【每日一题025】1000-digit Fibonacci number
drracket吧
全部回复
仅看楼主
level 11
The Fibonacci sequence is defined by the recurrence relation:
Fn = Fn
1 + Fn
2, where F1 = 1 and F2 = 1.
Hence the first 12 terms will be:
F1 = 1
F2 = 1
F3 = 2
F4 = 3
F5 = 5
F6 = 8
F7 = 13
F8 = 21
F9 = 34
F10 = 55
F11 = 89
F12 = 144
The 12th term, F12, is the first term to contain three digits.
What is the first term in the Fibonacci sequence to contain 1000 digits?
2014年04月16日 06点04分 1
level 11
#lang racket
;;;每日一题025
(define (prog025 n)
(let loop ((a 1) (b 1) (c 1))
(cond ((= n (string-length (number->string a)))
(list c a))
(else
(loop b (+ a b) (add1 c))))))
(prog025 3)
(prog025 1000)
===================
'(12 144)
'(4782
1070066266382758936764980584457396885083683896632
15166501323
520337531452060469404062
18891475824
89792657804694888177591957484336466672569959512996030461262748092482
18614406943
3051234774442750273781753087579391666192149259
18675955396
64228371489431
13074699503
4395470019854326097230672901928705264472437261177
15821825548
4911205250
13201478612
96593
13817922355
59657452039506
13755146783
7543229119602129934048260706175397706847068202895486902666
18543512452
190036948064
13574474709
1170761976694569107009802439343961747410373691250323
13655321647
7369702316775505
15951735184
605799549194109677783732296657965816465
13903488154
256310
18422419025
9846088000110
18625555024
54939371
13651657039
4476295847145485234259504285824253060835444354282126110089928637950480068943303097732178348645431
13205765659
8684562886168087
18693835297
35064398629764066000072356291790520705116407761481249
18858309459
40566688339109350944456576357666
15161931775
379289166
15813271596
1687748798382
18204925203
484738743847367719345127870292
18636250627
816)
2014年05月02日 11点05分 2
1