Revenge of Fibonacci
Time limit5sMemory limit128 MB
For each of up to 50,000 queries, find the smallest Fibonacci index below 100,000 whose decimal representation starts with the given digit string, or print -1.
- Level
Medium7 of 10
- Topics
- Math, Binary search, Implementation, Sorting
- Solved
- No attempts yet
Problem
The Fibonacci sequence is defined as follows.
- (for )
Here is called the index of the Fibonacci number .
The Fibonacci sequence has been studied for a very long time, and countless properties are known today. Seonyeong loves studying Fibonacci numbers even more than coding. After reading many papers on them, she came to believe there was no new property left to discover.
That night, Fibonacci appeared in her dream and said: "There is still an important property left unknown. For example, the Fibonacci number 347746739..."
Seonyeong woke up and tried to recall the rest of the digits, but she could not. So she decides to write a program to figure out what that number is.
Given the leading digits of some Fibonacci number, write a program that finds the smallest index among the Fibonacci numbers that start with those digits.
Input
The first line contains the number of test cases ().
Each test case consists of a single line containing the leading digits of some Fibonacci number. This number has at most 40 digits and has no unnecessary leading zeros.
Output
For each test case, print one line in the format Case #x: y, where is the test case number (starting from 1) and is the smallest index among the Fibonacci numbers that start with the given digits.
If no Fibonacci number with an index smaller than 100,000 starts with the given digits, print in place of .