新增 260321/100以内的素数.cpp
This commit is contained in:
26
260321/100以内的素数.cpp
Normal file
26
260321/100以内的素数.cpp
Normal 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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user