哪错了

Duke 2020-03-04 20:01:56 2020-03-05 20:04:20 15
#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;
}
{{ vote && vote.total.up }}

共 5 条回复

Duke

哦哦,懂了谢谢老师

Duke

哦哦,懂了谢谢老师

Duke

哦哦,懂了谢谢老师

root 站长

这句话用问题 for (int i = 2; i <= n; i ++ ), n 是本身,整除不能说明他不是素数,懂了没?

Duke

哪个大神帮下忙