a104: Fibonacci sequence
Tags :
Accepted rate : 129人/145人 ( 89% ) [非即時]
評分方式:
Tolerant

最近更新 : 2025-05-05 13:06

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 (50%): 1.0s , <1K
公開 測資點#1 (50%): 1.0s , <1K
Hint :
Tags:
出處:
[管理者:
kichan@g.pui... (陳嘉賢CHAN KA IN)
]


ID User Problem Subject Hit Post Date
2075
1652274-5@g.... (P6A05何承禧)
a104
Tricks
109 2025-05-14 16:31