## CCO '98 P1 - Fibonacci Numbers

View as PDF

Points: 10
Time limit: 2.0s
Memory limit: 64M

Problem type
Allowed languages
C, C++, ObjC, Pascal
##### Canadian Computing Competition: 1998 Stage 2, Day 1, Problem 1

The th Fibonacci number, , is defined thus:

Write a program that reads several , one per line, and writes the corresponding , one per line. Each value of will be between and . 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

• AryanG  commented on June 8, 2019, 12:23 p.m.

Sorry I just checked again I have a few issues I just found.

• AryanG  commented on June 6, 2019, 9:34 a.m.

Why does the judge keep saying my answer is wrong even though it works on repl.it

• wleung_bvg  commented on June 6, 2019, 10:38 a.m.

Your answers are incorrect for (somewhat) large values of .

• AryanG  commented on June 8, 2019, 12:18 p.m. edited

I have double checked the numbers my program is outputting and they are exactly correct. Also, the judge fails me for a relatively low value of fib(20).

• cup_of_tea  commented on Sept. 18, 2019, 8:24 a.m.

I think the submission feedback is troncated, displaying only the first elements (even if they are correct).

I had a similar error for very big results, but I had the same reaction, fib(20) being the last line displayed in feedback, while I was sure it was working for this input.

Maybe verify very big results (like 200) using a webgenerator for fibonaccis number.

• wleung_bvg  commented on Sept. 18, 2019, 4:05 p.m.

The issue AryanG had was actually related to how the answers were stored. In C++, long double is definitely not precise enough to store the correct answers for large values of .