233333

Duke 2020-03-06 20:06:13 16

#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; } 为什么还是错了 emmmmmmm(⊙﹏⊙)

{{ vote && vote.total.up }}

共 3 条回复

liangruichen

#include <bits/stdc++.h> using namespace std;

bool isPrime(int number) // 判断是否是质数的子程序 { if (number <= 1) return false; for (int i = 2; i <= sqrt(number); i++) if (number % i == 0) return false; return true; }

int main() { freopen("prime.in", "r", stdin); freopen("prime.out", "w", stdout); int n; scanf("%d", &n); if (isPrime(n)) printf("%d is a prime number.", n); else printf("%d is not a prime number.", n); fclose(stdin); fclose(stdout); return 0; }

Duke

233333

pikahuan 逗比

谢谢啊,但你为什么不提前几个月捏,我早就做过了