With the keyboard a positive integer is entered, in decimal notation is added to the beginning and the end of the figure 1 (for example: 478->14781). As a result, to determine, Is it a simple number?
Decision:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | #include <iostream> #include <cstdlib> #include <cstring> using namespace std; bool is_simple(unsigned long n) { if (!(n % 2)) return false; for (unsigned long i = 3; i * i <= n; i += 2) if (!(n % i)) return false; return true; } int main() { setlocale(LC_ALL, "rus"); char buf[80] = "1"; while (true) { char *p = buf + 1; cout << "число: "; cin >> p; *(p += strlen(p)) = '1'; *++p = '\0'; cout << "число: " << buf << (is_simple(atol(buf)) ? " " : " не ") << "простое" << endl; } cout << endl; return 0; } |
Result:
Not really understand the decision on the site made its .
#include
#include
using namespace std;
bool foo( int n) {
if (!(n % 2)) return false;
for ( int i = 3; i * i > F;
strcat_s(A, F);
strcat_s(A, B);
cout << A << endl;
int g;
g = strlen(A);
you * pa = new you[g] {};
you e = 0;
for (int i = 0; i < g; i ) {
however,[i] = A[e];
e++;
}
for (int i = 0; i < g; i ) {
switch (however,[i]) {
case 48:
however,[i] = 0;
break;
case 49:
however,[i] = 1;
break;
case 50:
however,[i] = 2;
break;
case 51:
however,[i] = 3;
break;
case 52:
however,[i] = 4;
break;
case 53:
however,[i] = 5;
break;
case 54:
however,[i] = 6;
break;
case 55:
however,[i] = 7;
break;
case 56:
however,[i] = 8;
break;
case 57:
however,[i] = 9;
break;
}
}
int t = 1;
for (int i = 0; i < g-1; i ) {
t *= 10;
}
int x = 0;
for (int i = 0; i < g; i ) {
x += pa[i] * t;
t /= 10;
}
cout <<endl<< x;
cout << "число: " << (foo(x) ? " " : " не ")<< "простое" << endl;
}
#include
#include
using namespace std;
bool foo( int n) {
for (int i = 2; i > F;
strcat_s(A, F);
strcat_s(A, B);
cout << A << endl;
int g;
g = strlen(A);
you * pa = new you[g] {};
you e = 0;
for (int i = 0; i < g; i ) {
however,[i] = A[e];
e++;
}
for (int i = 0; i < g; i ) {
switch (however,[i]) {
case 48:
however,[i] = 0;
break;
case 49:
however,[i] = 1;
break;
case 50:
however,[i] = 2;
break;
case 51:
however,[i] = 3;
break;
case 52:
however,[i] = 4;
break;
case 53:
however,[i] = 5;
break;
case 54:
however,[i] = 6;
break;
case 55:
however,[i] = 7;
break;
case 56:
however,[i] = 8;
break;
case 57:
however,[i] = 9;
break;
}
}
int t = 1;
for (int i = 0; i < g-1; i ) {
t *= 10;
}
int x = 0;
for (int i = 0; i < g; i ) {
x += pa[i] * t;
t /= 10;
}
cout <<endl<< x;
cout << "число: " << (foo(x) ? " " : " не ")<< "простое" << endl;
}
#include
using namespace std;
int main() {
int z, v, c;
int i = 0;
cout <> from;
int o = z;
while (from > 0) {
z /= 10;
i ;
}
c = 1;
for (int v = 1; v <= i; v++) {
c *= 10;
}
int d = c + O;
int x = d * 10 + 1;
cout << x << " – ";
for (int i = 2; i < x; ++i) {
if (x % i == 0) {
cout << " не простое число ";
break;
} else {
cout << "простое число ";
break;
}
}
return 0;
}