C++ 质数判断:打开门的密码
#include
bool isPrime(int num) { if (num < 2) { return false; } for (int i = 2; i <= num / 2; i++) { if (num % i == 0) { return false; } } return true; }
int main() { int n, x, y; cin >> n >> x >> y;
if (isPrime(x) && isPrime(y) && (x + y == n)) {
cout << 'yes';
} else {
cout << 'no';
}
return 0;
}
原文地址: https://www.cveoy.top/t/topic/qfZL 著作权归作者所有。请勿转载和采集!