# PAT 2019甲级春季考试真题1 Sexy Primes

Sexy primes are pairs of primes of the form (), so-named since "sex" is the Latin word for "six". (Quoted from http://mathworld.wolfram.com/SexyPrimes.html)

Now given an integer, you are supposed to tell if it is a sexy prime.

### Input Specification:

Each input file contains one test case. Each case gives a positive integer  ().

### Output Specification:

For each case, print in a line Yes if  is a sexy prime, then print in the next line the other sexy prime paired with  (if the answer is not unique, output the smaller number). Or if  is not a sexy prime, print No instead, then print in the next line the smallest sexy prime which is larger than .

### Sample Input 1:

47

### Sample Output 1:

Yes
41

### Sample Input 2:

21

### Sample Output 2:

No
23

#include <bits/stdc++.h>
using namespace std;

bool isPrime(int n){
if(n < 2) return false;
if(n == 2) return true;
for(int i = 2; i <= sqrt(n); i++){
if(n % i == 0) return false;
}
return true;
}

int judge(int num){
bool isp1 = isPrime(num);
bool isp2 = isPrime(num - 6);
bool isp3 = isPrime(num + 6);
if(isp1 && isp2) return num - 6;
if(isp1 && isp3) return num + 6;
return -1;
}

int main(){
int num;
cin >> num;
if(judge(num) != -1){
cout << "Yes\n" << judge(num) << endl;
return 0;
}else{
do{
num++;
}while(judge(num) == -1);
cout << "No\n" << num << endl;
}
return 0;
}