C++ |
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
| #include<iostream>
#include<string.h>
#include<math.h>
using namespace std;
int numlenth(unsigned long num)
{
int i;
for ( i = 1; num /= 10; ++i )
;
return i;
}
bool is_simple (unsigned long num)
{
if (num <= 1)
return false;
for(unsigned long del=2; del<num; del++)
if( num % del==0)
return false;
return true;
}
bool is_interesting(unsigned long num)
{
if(!is_simple(num))return false;
if(numlenth(num)<=1) return false;
unsigned long test1=num,test2=num;
for (int i = numlenth(num)-1; i > 0 ; i--)
if(!is_simple(test2= test2 % (unsigned long)(pow((float)10,i))))
return 0;
for(int i=1; i<numlenth(num); i++)
if (!is_simple(test1/=10))
return 0;
return 1;
}
int main ()
{
setlocale(LC_ALL,"rus");
cout<<"поиск чисел\n";
unsigned long iterator=10;
int count=0, sum=0;
while(count<11)
{
if(is_interesting(iterator))
{
count++;
sum+=iterator;
cout<<iterator<<" целевое число длиной "<<numlenth(iterator)<<", сумма "<<count<<" чисел равна "<<sum<<endl;
}
iterator++;
}
system("pause");
return 0;
} |
|
тут с проверкой..
ток вот хз - какого размера 11ое число.. чето оно не находится.