新增 260321/100以内的素数.cpp

This commit is contained in:
2026-03-21 07:11:13 -04:00
parent 0087ebeeb0
commit 9c8894defc

View File

@@ -0,0 +1,26 @@
#include <iostream>
using namespace std;
int main() {
for (int n = 2; n <= 100; n++) {
bool x = true;
// i*i <=n因数是成对出现的任何一个合数 ,都可以写成两个数相乘:
//n = a * b
//比如 n = 16它的因数对有
//2 * 8 = 16
//4 * 4 = 16
//8 * 2 = 16
for (int i = 2; i * i <= n; i++) {
if (n % i == 0) {
x = false;
break;
}
}
if (x) {
cout << n << " ";
}
}
return 0;
}