вот. квадратный корень только костылём находится.
C++ |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
| #include <iostream>
#include <math.h>
#include <conio.h>
using namespace std;
int main () {
int n;
bool f;
cin >> n;
for (int i = 1; i <=n; i++) {
f = true;
for (int j = 2; j <= (int) sqrt((double)i); j++)
if (i % j == 0) {
f = false;
break;
}
if (f) cout << i << endl;
}
getch();
return 0;
} |
|