CCO '98 P1 - Fibonacci Numbers

View as PDF

Submit solution

Points: 7
Time limit: 1.0s
Memory limit: 64M

Problem type
Allowed languages
Brain****, C, C++, Pascal, Rust
Canadian Computing Competition: 1998 Stage 2, Day 1, Problem 1

The nth Fibonacci number, f(n), is defined thus:

\displaystyle \begin{cases}
f(1) = 1 \\
f(2) = 1 \\
f(n) = f(n-1) + f(n-2) & \text{for all } n > 2
\end{cases}

Write a program that reads several n, one per line, and writes the corresponding f(n), one per line. Each value of n will be between 1 and 200. The last line of input contains 0.

Sample Input

1
2
3
4
5
100
0

Sample Output

1
1
2
3
5
354224848179261915075

Comments

There are no comments at the moment.