酷代码 AI
菜单
服务商

请你编写一个程序,输入a和b,判断它们俩是否都是素数。如果都是素数输出"yes",否则输出"no"。 输入: 两个数a和b。 输出: 如果都是素数输出"yes",否则输出"no"。 输入样例: 5 7 输出样例: yes c++

```cpp #include <iostream> #include <cmath> using namespace std; bool isPrime(int n) { if (n <= 1) return false; if (n == 2) return true; if (n % 2 == 0) return false; int limit = sqrt(n); for (int i = 3; i <= limit; i += 2) { if (n % i == 0) return false; } return true; } int main() { int a, b; cin >> a >> b; if (isPrime(a) && isPrime(b)) { cout << "yes" << endl; } else { cout << "no" << endl; } return 0; } ``` [2025-12-20 14:34:24 | AI问答 | 168点数解答]

相关提问
发财导航,免费问AI
实用工具查看更多