Twin Guardians

시간 제한1초메모리 제한2048 MB

요약
테스트 케이스마다 두 수가 주어질 때, 둘 다 소수이고 차이가 2인 쌍둥이 소수인지 판정합니다.
난이도

쉬움10점 중 2점

유형
수학, 정수론, 완전 탐색
정답자
아직 제출이 없습니다

문제

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.

제한

  • 1≤t≤101 ≤ t ≤ 10
  • 1≤a<b≤1061 ≤ a < b ≤ 10^6

예제2

  1. 예제 1

    입력
    5
    2 3
    11 13
    12 14
    3 5
    5 7
    
    예상 출력
    N
    Y
    N
    Y
    Y
    
  2. 예제 2

    입력
    5
    17 19
    29 31
    15 17
    19 21
    41 43
    
    예상 출력
    Y
    Y
    N
    N
    Y