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 and then repeatedly adding squares in clockwise order with the side length of the th square being equal to the . By doing this, a rectangle will always be formed. Here is a diagram:
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 , can you figure out which Fibonacci square the coordinate is in?
The standard input will contain 10 datasets. Each dataset consists of two space-separated integers , representing a point on the plane.
For each dataset, output the smallest integer such that the point is contained (or is on the boundary of) a square of side length .
Sample Input (5 Datasets Shown)
0 0 1 1 2 1 3 -2 -9 0
1 3 4 5 6
Educational Computing Organization of Ontario - statements, test data and other materials can be found at ecoocs.org