Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding
Ninjas X Naukri.com

Problem of the day

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.

```
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

```
1 <= T <= 1000
2 <= N <= 10^6
Time limit: 1 sec
```

```
2
4
2
```

```
Yes
No
```

```
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.
```

```
3
3
18
25
```

```
No
Yes
No
```