一共三种情况
- n与n-6性感输出n-6
- n与n+6性感输出n+6
- n不性感输出最近的性感的数
判断一下即可
#include <iostream>
#include <math.h>
using namespace std;
int n;
bool check(int n) {
if(n<=1) return false;
for(int i=2; i<=sqrt(n); i++)
if(n%i==0) return false;
return true;
}
int get(int n) {
if(check(n)&&(check(n-6)||check(n+6)))
if(check(n-6)) return 1;
else return 2;
else return 0;
}
int main() {
cin >> n;
if(get(n)==1) cout << "Yes\n" << n-6;
else if(get(n)==2) cout << "Yes\n" << n+6;
else {
while(get(n)==0)
n++;
cout << "No\n" << n;
}
return 0;
}