Moderate
0/80
Average time to solve is 10m
Contributed by
0 upvote

## Problem statement

A prime adjacent is a number that is adjacent to two prime numbers. Two numbers are considered adjacent to each other if the absolute difference between them is 1.

For Example:
``````4 is a prime adjacent because it is adjacent to the numbers 3 and 5, which are prime numbers.
``````

Your task is to find out if the number given to you is prime adjacent or not.

Detailed explanation ( Input/output format, Notes, Images )
Input Format :
``````The first line contains an integer 'T' which denotes the number of test cases or queries to be run. Then, the T test cases follow.

The first and only line of each test case or query contains an integer N.
``````
Output format:
``````For each test case, print “Yes” if N is prime adjacent, otherwise print “No” (without inverted commas), in a separate line.
``````
Constraints:
``````1 <= T <= 1000
2 <= N <= 10^6

Time limit: 1 sec
``````
##### Sample Input 1:
``````2
4
2
``````
##### Sample Output 1 :
``````Yes
No
``````
##### Explanation :
``````For test case 1:
4 is a prime adjacent because its adjacent numbers, 3 and 5 are prime numbers.

For test case 2:
In case of 2, the adjacent numbers are 1 and 3, out of which 1 is not prime but 3 is
prime.

By definition, a number is a prime adjacent only if both of its adjacent numbers are prime numbers. So, 2 is not a prime adjacent.
``````
##### Sample Input 2:
``````3
3
18
25
``````
##### Sample Output 2 :
``````No
Yes
No
``````
Console