a104: Fibonacci sequence
Tags :
Accepted rate : 112人/125人 ( 90% ) [非即時]
評分方式:
Tolerant

最近更新 : 2022-08-18 01:55

Content

The Fibonacci Sequence is the series of numbers:

0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ...

The next number is found by adding up the two numbers before it:

  • the 2 is found by adding the two numbers before it (1+1),
  • the 3 is found by adding the two numbers before it (1+2),
  • the 5 is (2+3),
  • and so on!

The recursion formula is : f(x) = f(x-1)+f(x-2)

Given a integer n, your task is to print out the first nFibonacci numbers

 
Input

an integer n

1<n<50

Output

a list of integers separated by a space represent the first n Fibonacci numbers

Sample Input #1
5
Sample Output #1
0 1 1 2 3
Sample Input #2
7
Sample Output #2
0 1 1 2 3 5 8
Sample Input #3
10
Sample Output #3
0 1 1 2 3 5 8 13 21 34 
測資資訊:
記憶體限制: 64 MB
公開 測資點#0 (33%): 1.0s , <1K
公開 測資點#1 (33%): 1.0s , <1K
公開 測資點#2 (34%): 1.0s , <1K
Hint :
Tags:
出處:
[管理者:
kichan@g.pui... (陳嘉賢CHAN KA IN)
]


ID User Problem Subject Hit Post Date
1662
1650139-x@g.... (P6D33溫庭昊)
a104
小心
69 2024-08-03 18:16