1
0
forked from newde/homework
Files
homework/260321/100以内的素数.cpp

26 lines
579 B
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#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;
}