Frieze Patterns |
1 1 1 1 1 1 . 2 1 3 1 . . . 1 2 2 1 . . . 1 1 1 1 1 1 .
Each line of the output corresponds to a test case. The line must include a unique integer
value corresponding to the value in the position (i, j)
A frieze pattern has k
2
A
B C
D
satisfies the relationship B*C = A*D + 1
John has the idea of using integer frieze patterns in his designs (for example, using colors instead of numbers), and he knows, from a given sequence of integer values for the first column, if an integer frieze pattern follows. For this setting, he wants to know the value of a position in an integer frieze pattern, given the values of the first column.
Input
The input consists of several test cases. The first line of each test case is an integer value N
1000
1000
i
N
The end of the input is recognized by a number 0
Output
Sample Input
4
2 3
1 2 1 1
6
5 9
1 1 1 1 2 1
0
Sample Output
3
4
Colombia'2008