- MysGln 的博客
7月17日
- @ 2026-7-17 13:22:53
#include <bits/stdc++.h>
using namespace std;
int main() {
// 关于质数(素数)判定
// def. 质数:因数只有1和它本身,特别的 1 不是质数?
// 证明一个整数 x 它不是质数 <==> 因数个数 (2)
// 1. 全循环 从 1 循环到自身,统计因数个数
int x;
cin >> x;
int cnt = 0;
for (int i = 1; i <= x; i++) {
if (x % i == 0) {
cnt++;
}
}
if (cnt == 2) cout << "yes" << endl;
else cout << "no" << endl;
// 2. 2~x-1
bool ok = true; // 假设当前的 x 是质数,如果找到一个反例说明其不是
for (int i = 2; i <= x - 1; i++) {
if (x % i == 0) {
ok = false;
break;
}
}
if (ok == true) cout << "yes" << endl;
else cout << "no" << endl;
// 3. 2~sqrt(x)
bool ok = true;
for (int i = 2; i <= sqrt(x); i++) {
if (x % i == 0) {
ok = false;
break;
}
}
return 0;
}
T2
#include <bits/stdc++.h>
using namespace std;
int main() {
// max、min 求最大值、求最小值
int a = 1, b = 2;
cout << max(a, b) << endl;
cout << min(a, b) << endl;
int c = 8, d = 10;
cout << max({a, b, c, d}) << endl;
cout << min({a, b, c, d}) << endl;
int n = max({a, b, c, d});
// pow(a, b) = a^b
// pow(2, 3) = 8
// pow(3, 2) = 9
// sqrt(16) = 4
// sqrt(9) = 3
return 0;
}