|素数判断 while|19春第一题1156 Sexy Primes (20 分)
#include <iostream>using namespace std;bool isP(int n) {if (n <= 1)return false;for (int i = 2; i <=sqrt(n); i++) {if (n % i == 0)return false;}return true;}int isSexyPrime(int n) {if (isP
·
#include <iostream>
using namespace std;
bool isP(int n) {
if (n <= 1)return false;
for (int i = 2; i <=sqrt(n); i++) {
if (n % i == 0)
return false;
}
return true;
}
int isSexyPrime(int n) {
if (isP(n) == true) {
if (isP(n - 6) == true) return n - 6;
if (isP(n + 6) == true) return n + 6;
}
return -1;
}
int main() {
int n;
cin >> n;
int ans = isSexyPrime(n);
if(ans!=-1)cout << "Yes\n" << ans;
else {
while (isSexyPrime(++n) == -1);
cout << "No\n"<<n;
}
return 0;
}
更多推荐
活动日历
查看更多
直播时间 2025-02-26 16:00:00


直播时间 2025-01-08 16:30:00


直播时间 2024-12-11 16:30:00


直播时间 2024-11-27 16:30:00


直播时间 2024-11-21 16:30:00


所有评论(0)