#include <bits/stdc++.h>
using namespace std;
int main() {
freopen("prime.in", "r", stdin);
freopen("prime.out", "w", stdout);
int n;
cin >> n;
for (int i = 2; i <= n; i++) {
if (n == 0) {
cout << n << " is a prime number.";
} else if (n % i == 0) {
cout << n << " is not a prime number.";
return 0;
} else if (n % i != 0) {
cout << n << " is a prime number.";
break;
}
}
fclose(stdin);
fclose(stdout);
return 0;
}
共 5 条回复
哦哦,懂了谢谢老师
哦哦,懂了谢谢老师
哦哦,懂了谢谢老师
这句话用问题
for (int i = 2; i <= n; i ++ )
, n 是本身,整除不能说明他不是素数,懂了没?哪个大神帮下忙