forked from Dashark/hello-world
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSuperPrime_HW.cpp
103 lines (78 loc) · 1.4 KB
/
SuperPrime_HW.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include <iostream>
#include<stdio.h>
int main() {
int p[1000] = {0};
int pp[1000] = {0};
int i = 2;
for(;i < 1000;i++){//筛数法
p[i] = i;
}
int j = 0;
i = 2;
for(; i < 1000;i++){//生成一个纯净的素数数组
if(p[i] == 0){
continue;
}
pp[j] = p[i];
//printf("A%d %d\n",pp[j],j);
j++;
int k = 2;
for(;(i * k) < 1000;k++){
p[i * k] = 0;
}
}
int ppn = j;
//printf("B%d\n",ppn);
//for(i = 0; i < j;i++){
// printf("C%d %d\n",pp[i],i);
//}
int sp;
int countsp = 0;
int sumsp = 0;
int max = 0;
int judge = 0;
int t;
for(t = 25; t < ppn;t++){
//printf("D%d\n",pp[t]);
sp = pp[t];
int g = sp % 10;
int s = (sp - g) % 100 / 10;
int b = (sp - 10 * s - g) / 100;
int sum = g + s + b;
int mul = g * s * b;
int mul2 = g * g + s * s + b * b;
//printf("E%d %d %d %d \n",sp,g,s,b);
judge = 0;
for(j = 0;j < ppn;j++){
if(pp[j] == sum){
judge++;
//printf("Q1\n");
break;
}
}
//printf("go\n");
for(j = 0;j < ppn;j++){
if(pp[j] == mul){
judge++;
//printf("Q2\n");
break;
}
}
;
for(j = 0;j < ppn;j++){
if(pp[j] == mul2){
judge++;
//printf("Q3\n");
break;
}
}
if(judge == 3){
countsp++;
sumsp += sp;
max = sp;
//printf("Q%d\n",sp);
}
}
printf("个数:%d 和:%d 最大:%d \n",countsp,sumsp,max);
return 0;
}