-
Notifications
You must be signed in to change notification settings - Fork 0
/
eu0029.cpp
170 lines (158 loc) · 5.4 KB
/
eu0029.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#include"eu0029.h"
#include"principal.h"
void eu0029 :: solucion(){
// ---------------------------------------------------- //
tstart = (double)clock()/CLOCKS_PER_SEC;
// ---------------------------------------------------- //
output = 0;
// Numeros Primos
tem_1d_1 = new unsigned long long[27];
// Contador de los numeros que solo tienen un factor primo
tem_1d_2 = new unsigned long long[600];
// Contador de los numeros que tienen 2 factores primos
tem_2d_1 = new unsigned long long *[500];
for( unsigned long long i=0; i<500; i++ ){
tem_2d_1[i] = new unsigned long long[300];
}
// Contador de los numeros que tienen 3 factores primos
tem_3d_1 = new unsigned long long **[200];
for( unsigned long long i=0; i<200; i++ ){
tem_3d_1[i] = new unsigned long long*[200];
for( unsigned long long j=0; j<200; j++ ){
tem_3d_1[i][j] = new unsigned long long[100];
}
}
// Inicializa a cero todo
for( unsigned long long l=0; l<600; l++ ){
tem_1d_2[l] = 0;
}
for( unsigned long long l=0; l<500; l++ ){
for( unsigned long long m=0; m<300; m++ ){
tem_2d_1[l][m] = 0;
}
}
for( unsigned long long l=0; l<200; l++ ){
for( unsigned long long m=0; m<200; m++ ){
for( unsigned long long n=0; n<100; n++ ){
tem_3d_1[l][m][n] = 0;
}
}
}
// ---------------------------------------------------- //
// Busca los numeros primos debajo de 100 (toca encontrar dos mas el 101 y 107 porque sino tengo problemas con los for anidados
// pues los dos de mas abajo utlizan el tipico esquema i+1, i+2 // SE ME OLVIDO Q ESTO SE PUEDE RESOLVER CON UN ESQUEMA DONDE EL
// FOR ESTE DEBAJO, ALGO ASI COMO UN DO{}WHILE
temp_1 = 0;
for( unsigned long long i=2; i<109; i++ ){
if( isprime(&i)){
tem_1d_1[temp_1] = i;
temp_1 = temp_1 + 1;
}
}
// Estas variables son las que me dicen la multiplicidad de los numeros primos
temp_4 = 1;
temp_5 = 0;
temp_6 = 0;
for( unsigned long long i=0; i<25; i++ ){
temp_1 = tem_1d_1[i];
for( unsigned long long j=i+1; j<25+1/*2*/; j++ ){
temp_2 = tem_1d_1[j];
temp_7 = pow(temp_1,temp_4)*pow(temp_2,temp_5);
if( temp_7<=100 ){
for( unsigned long long k=j+1; k<25+2; k++ ){
// Este esquema de fores me asegura la base del A^B, es decir el A
// Lo que aseguro es que me van a pasar 3 numeros primos en orden lexicografico
// es decir primero el 2 3 5, luego el 2 3 7, etc.., sin repetir
temp_3 = tem_1d_1[k];
temp_7 = pow(temp_1,temp_4)*pow(temp_2,temp_5)*pow(temp_3,temp_6);
// Estos whiles manejan el cuento de las multiplidades, empezando con la minima multiplicidad
// que es 0, y luego siguiendo aumentando dicha multiplicidad, por eso nunca entro con numeros primos
// repeticos (orden lexicografico) sino que todo lo dejo en manos d estos whiles que prueban todas
// las combinaciones de multiplicidades distintas
while( temp_7 <= 100 ){
while( temp_7 <= 100 ){
while( temp_7 <= 100 ){
// Los que tienen un solo numero primo
if( temp_4>=1 && temp_5==0 && temp_6==0 ){
// Se analiza la parte del exponente, de 2 a 100
for( unsigned long long l=2; l<=100; l++ ){
// if( temp_4*l > 100 ){
// temp_sig_1 = temp_4*l-1;
tem_1d_2[temp_4*l-1] = 1;
// }
}
}
// Los que tienen dos numeros primos distintos como factor
else if( temp_4>=1 && temp_5>=1 && temp_6==0 ){
for( unsigned long long l=2; l<=100; l++ ){
tem_2d_1[temp_4*l-1][temp_5*l-1] = 1;
}
}
// Los que tienen tres numeros primos distintos como factor
else if( temp_4>=1 && temp_5>=1 && temp_6>=1 ){
for( unsigned long long l=2; l<=100; l++ ){
tem_3d_1[temp_4*l-1][temp_5*l-1][temp_6*l-1] = 1;
}
}
temp_4 = temp_4 + 1;
temp_7 = pow(temp_1,temp_4)*pow(temp_2,temp_5)*pow(temp_3,temp_6);
}
temp_5 = temp_5 + 1;
temp_4 = 1;
temp_7 = pow(temp_1,temp_4)*pow(temp_2,temp_5)*pow(temp_3,temp_6);
}
temp_6 = temp_6 + 1;
temp_5 = 1;
temp_4 = 1;
temp_7 = pow(temp_1,temp_4)*pow(temp_2,temp_5)*pow(temp_3,temp_6);
}
// Contar e inicializar los contadores a cero
// Es decir, se cuenta cuantos numeros hay por cada tipo de configuracion, cuantos para un solo
// numero primo distinto, cuantos para dos, cuantos para tres
for( unsigned long long l=0; l<600; l++ ){
if( tem_1d_2[l] == 1 ){
output = output + 1;
tem_1d_2[l] = 0;
}
}
for( unsigned long long l=0; l<500; l++ ){
for( unsigned long long m=0; m<300; m++ ){
if( tem_2d_1[l][m] == 1 ){
output = output + 1;
tem_2d_1[l][m] = 0;
}
}
}
for( unsigned long long l=0; l<200; l++ ){
for( unsigned long long m=0; m<200; m++ ){
for( unsigned long long n=0; n<100; n++ ){
if( tem_3d_1[l][m][n] == 1 ){
output = output + 1;
tem_3d_1[l][m][n] = 0;
}
}
}
}
temp_4 = 1;
temp_5 = 1;
temp_6 = 1;
}
}
temp_4 = 1;
temp_5 = 1;
temp_6 = 0;
}
temp_4 = 1;
temp_5 = 0;
temp_6 = 0;
}
// ---------------------------------------------------- //
tstop = (double)clock()/CLOCKS_PER_SEC;
ttime= tstop-tstart;
// ---------------------------------------------------- //
}
void eu0029 :: printsolution(){
cout << "Euler 0029\n";
cout << "Time: " << ttime << "\n";
cout << output;
}