Problems
A Famous Grid
A Famous Grid
Mr. B has recently discovered the grid named "spiral grid".
Construct the grid like the following figure. (The grid is actually infinite. The figure is only a small part of it.)
\includegraphics{https://static.e-olymp.com/content/42/427ea1a97ca013708d26c4b238d624da19832252.jpg}
Considering traveling in it, you are free to any cell containing a composite number or 1, but traveling to any cell containing a prime number is disallowed. You can travel up, down, left or right, but not diagonally. Write a program to find the length of the shortest path between pairs of nonprime numbers, or report it's impossible.
\includegraphics{https://static.e-olymp.com/content/95/958514f11426ceca699c95979192187033be5cba.jpg}
\InputFile
Each test case is described by a line of input containing two nonprime integer \textbf{1} ≤ \textbf{x}, \textbf{y} ≤ \textbf{10000}.
\OutputFile
For each test case, display its case number followed by the length of the shortest path or "\textbf{impossible}" (without quotes) in one line.
Input example #1
1 4 9 32 10 12
Output example #1
Case 1: 1 Case 2: 7 Case 3: impossible