forked from Dashark/hello-world
-
Notifications
You must be signed in to change notification settings - Fork 0
/
超级素数.cpp
53 lines (52 loc) · 1.24 KB
/
超级素数.cpp
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<stdio.h>
#include<iostream>
#include<stdbool.h>
using namespace std;
class judge{
public:
bool sushu(int n,bool light)
{
light=0;
int b=0;
for(int a=2;a<n;a++)
{if(n%a==0){b++;}}
if(b==0){light=1;}
return light;
}
bool super(int c,bool light)
{
light=1;
int ge,shi,bai,he,ji,ping,a,b=0;
ge=c%10;shi=((c-ge)%100)/10;bai=(c-ge-shi*10)/100;
he=ge+shi+bai;ji=ge*shi*bai;ping=ge*ge+shi*shi+bai*bai;
if(ge!=0&&shi!=0&&bai!=0)
{for(int a=2;a<he;a++){if(he%a==0){b++;}}if(b!=0) {light=0;}
if(light==1){for(int a=2;a<ji;a++){if(ji%a==0){b++;}}
if(b!=0) {light=0;}}
if(light==1){for(int a=2;a<ping;a++){if(ping%a==0){b++;}}
if(b!=0) {light=0;}}}
else light=0;
return light;
}
};
int main()
{
int n,sushu[255]={},super[255]={},num=0,a2=0;
judge M;bool light;
for(n=100;n<=999;n++)
{light=M.sushu(n,light);
if(light==1){sushu[num]=n;num++;}
}
num=0;
for(n=100;n<=999;n++)
{light=M.super(n,light);
if(light==1){super[num]=n;printf("%d %d\n",super[num],num);num++;}
}
cout<<"¸öÊý="<<num<<endl;
num--;
for(n=0;n<=num;n++)
{a2=a2+super[n];}
cout<<"ºÍ="<<a2<<endl;
cout<<"×î´ó="<<super[num]<<endl;
return 0;
}