Pro.ID10036 TitleA Famous Grid Title链接http://10.20.2.8/oj/exercise/problem?problem_id=10036 AC2 Submit2 Ratio100.00% 时间&空间限制描述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.) 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. 输入Each test case is described by a line of input containing two nonprime integer 1 ≤ x, y ≤ 10,000. 输出Description 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.) 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. Input Each test case is described by a line of input containing two nonprime integer 1 ≤ x, y ≤ 10,000. Output For each test case, display its case number followed by the length of the shortest path or "impossible" (without quotes) in one line. Sample Input 1 4 Sample Output Case 1: 1 Source 样例输入1 4 样例输出Case 1: 1 作者 |