10036_AFamousGrid

2022-5-16 18:16| 发布者: Hocassian| 查看: 75| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-3-89504360421099-Problem List-采集的数据-后羿采集器.html

Pro.ID

10036

Title

A Famous Grid

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=10036

AC

2

Submit

2

Ratio

100.00%

时间&空间限制

  • Time Limit: 6000/3000 MS (Java/Others)     Memory Limit: 65536/32768 K (Java/Others)
  • 描述

    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
    9 32
    10 12

    Sample Output

    Case 1: 1
    Case 2: 7
    Case 3: impossible

    Source

    样例输入

    1 4
    9 32
    10 12

    样例输出

    Case 1: 1
    Case 2: 7
    Case 3: impossible

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部