The Fibonacci sequence can be represented as follows:
- The first two Fibonacci numbers,
and , are both equal to . - For
, the th Fibonacci number is the sum of the two previous ones, i.e. .
The first few terms of the sequence are
An interesting way to represent this sequence is by starting as a square with a side length equal to
This process can be repeated indefinitely, which means that we can cover the plane using these Fibonacci squares. Suppose we repeat the process as shown in the diagram above with the top-left corner of the first square being the origin
Given a coordinate
Input Specification
The standard input will contain 10 datasets. Each dataset consists of two space-separated integers
Output Specification
For each dataset, output the smallest integer
Sample Input (5 Datasets Shown)
0 0
1 1
2 1
3 -2
-9 0
Sample Output
1
3
4
5
6
Educational Computing Organization of Ontario - statements, test data and other materials can be found at ecoocs.org
Comments