Fibonacci
Time limit1sMemory limit128 MB
Read integers n until -1 and print F_n mod 10000 for each, with n up to one billion.
- Level
Medium4 of 10
- Topics
- Math, Matrix, Divide and conquer
- Solved
- No attempts yet
Problem
In the Fibonacci sequence, , , and for . For example, the first ten terms of the sequence are:
An equivalent formulation uses matrix exponentiation:
Given an integer , compute the last four digits of .
Input
The input contains multiple test cases. Each test case is a single line holding an integer with . The input ends with a single line containing , which is not part of the data.
Output
For each test case, print the last four digits of on its own line. If those four digits are all zero, print 0; otherwise omit any leading zeros. In other words, print .