#P15894. [TOPC 2025] Twin Guardians

    ID: 29349 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 1 上传者: 标签>数学2025素数判断,质数,筛法ICPC台湾

[TOPC 2025] Twin Guardians

题目描述

In a distant Mathematical Kingdom, there stands an ancient gate known as the “Twin Gate.” Legend has it that the gate will only open when two “Twin Guardians” stand before it at the same time.

The king has summoned a wise adventurer to help determine whether the two given numbers are “Twin Primes.” If they genuinely are Twin Guardians (i.e., Twin Primes), the gate will shine brightly and open; otherwise, it will remain firmly shut.

Definition of Twin Primes: If two numbers ii and i+2i+2 are both prime, they are called “twin primes.”

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt. The description of the test cases follows.

The only line of each test case contains two integers aa and bb, representing a task assigned by the king that asks you to check these two numbers.

输出格式

For each test case, if aa and bb are twin primes, output Y (indicating “Yes, the Twin Gate opens!”); otherwise, output N.

5
2 3
11 13
12 14
3 5
5 7
N
Y
N
Y
Y
5
17 19
29 31
15 17
19 21
41 43
Y
Y
N
N
Y

提示

  • 1t101 \le t \le 10
  • 1a<b1061 \le a < b \le 10^6