Repository navigation
Expand file tree
/
Copy pathP049.cpp
More file actions
103 lines (102 loc) · 3.42 KB
/
Copy pathP049.cpp
File metadata and controls
103 lines (102 loc) · 3.42 KB
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 <cstring>
using namespace std;
unsigned long long int P049(){
const unsigned int max=9999;
bool Pr[max]={0,0};
for(unsigned int i=2;i<max;i++){
Pr[i]=true;
}
for(unsigned int i=0;i<max;i++){
if(Pr[i]){
for(unsigned int j=2;j*i<max;j++){
Pr[i*j]=false;
}
}
}
{
unsigned int i=999;
while(true){
unsigned int L[24];
unsigned int Lm=0;
while(!Pr[++i]){
if(i>max){
cout<<"Fim"<<endl;
return 0;
}
}{
unsigned int Lt[24];
unsigned int Ltm=0;
unsigned char N[4]={(i/1000)%10,(i/100)%10,(i/10)%10,i%10};
for(unsigned int a=0;a<4;a++){
for(unsigned int b=0;b<4;b++){
if(b!=a){
for(unsigned int c=0;c<4;c++){
if(c!=a && c!=b){
for(unsigned int d=0;d<4;d++){
if(d!=a && d!=b && d!=c){
unsigned r=N[a]*1000+N[b]*100+N[c]*10+N[d]*1;
if(Pr[r]){
Lt[Ltm]=r;
Ltm++;
}
}
}
}
}
}
}
}
{
Lt[Ltm]=(unsigned int)-1;
unsigned int aux=Ltm;
Ltm++;
do{
for(unsigned int j=0;j<Ltm;j++){
if(Lt[j]<Lt[aux]){
aux=j;
}
}
if(Lt[aux]==(unsigned int)-1){
break;
}
if(!Lm || L[Lm-1]!=Lt[aux]){
L[Lm]=Lt[aux];
Lm++;
}
Lt[aux]=(unsigned int)-1;
}while(true);
}
}
/*
cout<<i<<":";
for(unsigned int j=0;j<Lm;j++){
cout<<L[j]<<"\t";
}
cout<<endl;
*/
if(Lm<2){
continue;
}
for(unsigned int j=0;j<Lm-2;j++){
for(unsigned int k=j+1;k<Lm;k++){
unsigned int r=2*L[k]-L[j];
for(unsigned int l=k+1;l<Lm;l++){
if(r<L[l]){
break;
}else if(r==L[l]){
cout<<"ACHEI"<<endl;
cout<<L[j]<<"\t"<<L[k]<<"\t"<<r<<endl;
}
}
}
}
}
}
return 0;
}
int main(){
cout<<"A resposta estara no segundo, pois o primeiro foi desconsiderado por nao ter 3330 como diferenca na progrecao"<<endl<<endl;
cout<<P049()<<endl;
return 0;
}