5.16 · exercise
Fibonacci goes large
Compute the nth Fibonacci number for the n the starter reads. With the 50 in the stdin box the answer is 12,586,269,025, which does not fit in 32 bits, so the loop has to run in x registers.
Keep the classic sliding pair: a and b start as 0 and 1, and n times over, the new value is a + b, then the pair slides forward. When the loop ends, a holds the answer.
What is checked
fib(50)printed on its own line- the program exits cleanly
- the loop builds it (answer not written in)
- the same holds for other values of
nyou do not see, fromfib(0)up tofib(92), the largest that fits in a signed 64-bit register
specification
stdin50
stdoutprints the right output
exitexits with the right code
sourceuses
addsourcedoes not hardcode the answer
hiddenright output and exit code on 4 more inputs you do not see
We run your program on the input above and on the hidden ones, and compare what it does. Nothing is matched against a stored solution.