diff --git a/07 - Primeros 10001 primos/tst b/07 - Primeros 10001 primos/tst index 288416e1f3b84728eab3b07c25e9d0f92618f083..d5c7887e6e99a452460f1918a8780f9a3e5da5d2 100755 GIT binary patch delta 2956 zcmZWre{56N6~6cR*?!MX;^#QQHc5#?lF@*g#4W>XX@diJJd^z4t;q%x44cFzW+C=$ zCv7@XQ-w@;85QQXnt~!NX{$<9Oe#vZRn-P&RQ3ALMk<6>wpO89ri5f&=qfd3X}xov z-(xIX$>-efeCNl#_nrHmueDF^J@YUZtj=zJz3p?6C_~ePxD-r58sN90@+)Fcv1>Zc zDUh6CR%*9OrXrF|MK6gxP7hg+3q|X3!K+M;v-9-T3e&b3PwqCVR&&*j}` zmpi6|oWMDyl43O0)hQ80(ZXKf?apthtPzZAafSA>i@?hFvHJUB1MC*RftH@tZ%p4c zxJaR46{Mxc3p2#M=(;dlfYI<7V%+z_H3i>BjFlF03jPE!u4~~<1>Z!>Bc258{--}P z^FulFi9GW63DK*(mWpYr`@%(o2N`508@ z50|W)2)Wz?=c4R${;{tM?0d#~XTXa@5wG>_zXIitUU z(=q*@QDuCyO3JRKj0BnJVwnQTXwEYF44jkYH@?FASMk^~!>eN@zSWUg3fxP%gI8IH z;HV~?3l9GDBdDM5XqQcR{}e`V?&UI_M5;3(!5FE1(6hGq<>jPO|-CGbgRGpNZdSYlV;(!G*MyNk8Rw zl^VEAi4iVXHHN|O0`TwtAAk8Cj|~)Hcf=YhGplKjJ`QC$HbZSJZi>4*)$8fRXc*cR zuPQ>K-eR&|#e`YSY3g8EbAd`MTQbE(C?s2#{s*j_SDXa;I%s|ah&K2Q8oVG0iQw&0 z2PYU`f+>DBsKEn>7luIU`;bWU zycrpRKMm0EBnWE$K1i*+a(rl=C;>ks9(>V(&ralrjXp3^Gg5r^Onz8+QC)Qk{BVe0 zf}o}4io;}nSo{!i8CKx3eIlR6c&QE~m;DhgEeVVXX|$QcFp)OF!nsD6m25@t21#Xk zqZej`ysJoHCe8tG#GarH#R>$J+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9+#w{HbSg!*pY z_ifRGn>wQFBF8jaIe$pZ*fki@w&TI+{HHO#N*W6EtQsXj8t^PdgX z1|FE7uKtdxU9~*W7{tR+eblv%{#A@d>>aUbx$m$IQEh&@j;&4W`dwrWV0QNH-v>ou=Bb0^T_dGNR;) zY;?fqqufU>>RRBnP_pzp;o(*x@t>{W>m)z)^MyA0F3`3ecnvb`d&JT683meH;pioi ze>CtRDZt7L?jdoL!E{2>u6#BlgTtolICojO6M?mm4+?)kDvE-G?-mua%odhhHdpf5 z|B$QXzS*kH?qib6tfZJUSgQD?kJE08Rh2EXCwX$wvPqRaOsI_qmQ8$@^m*GwYS&u% z9tri3Za_<)z85HxHX%yx1IkuRKdCLY^4SwhlI~)wHhUhaoJ>|6!H=6ss@Mp{dB1ow z^H?saE2-zV=Ps(t%w(X%$nR2Tn7d@S#L92gWKbW$rB?pBgjz^LsgNeG{{!w>1pWX3 diff --git a/07 - Primeros 10001 primos/tstP07.cpp b/07 - Primeros 10001 primos/tstP07.cpp index fa07e4b..5094217 100644 --- a/07 - Primeros 10001 primos/tstP07.cpp +++ b/07 - Primeros 10001 primos/tstP07.cpp @@ -1,43 +1,31 @@ #include #include -#define SIZE_ARRAY 1000000 +#define SIZE_ARRAY 10001 bool esPrimo(int eval, int *primosConocidos); bool esPar(int eval); -int contadorPrimos = 0; +int *lastAddr = 0; int main(int argc, char const *argv[]) { - - int *ptrPrime; int arrayPrime[SIZE_ARRAY] = { 0 }; int counter; - int counterTmp=0; - bool valido; - counter = 1; + //Agregando valores conocidos + arrayPrime[0] = 2; + arrayPrime[1] = 3; + //Init + counter = 3; do { - if (counter <= 2) - counter++; - else - counter+=2; - + counter+=2; valido = esPrimo(counter, arrayPrime); - - if(counterTmp != contadorPrimos && contadorPrimos % 100000 == 0) - { - counterTmp = contadorPrimos; - printf("%d\t-\t%d\n", counter, contadorPrimos); - } - - } while (arrayPrime[SIZE_ARRAY-1] == 0); printf("El primo #%d es:\t%d\n", SIZE_ARRAY, arrayPrime[SIZE_ARRAY-1]); @@ -46,55 +34,35 @@ int main(int argc, char const *argv[]) } - bool esPrimo(int eval, int *primosConocidos) { bool valido = true; double res = 0; - if(eval == 2) - { - //printf("Test: 2\n"); - *primosConocidos = 2; - valido = true; - } - /* - else if(esPar(eval)) - { - //printf("Test: par\n"); - valido = false; - } - */ - else + res = sqrt(eval); + while(*primosConocidos != 0) { - //printf("Test: SQRT\n"); - res = sqrt(eval); - while(*primosConocidos != 0) + if((double) *primosConocidos <= res) { - if((double) *primosConocidos <= res) + if ( eval % *primosConocidos == 0 ) { - //printf("Test: raiz menor\n"); - valido = (eval % *primosConocidos != 0); + valido = false; + break; } else { - //printf("Test: raiz mayor\n"); - - while(*primosConocidos != 0) { - primosConocidos++; - } - - //printf("%d\t", eval); - contadorPrimos++; - *primosConocidos = eval; - valido = true; - break; + primosConocidos++; } + } + else + { - if (!valido) break; - - primosConocidos++; + lastAddr = (lastAddr == 0) ? ++primosConocidos : lastAddr + 1; + primosConocidos = lastAddr; + *primosConocidos = eval; + valido = true; + break; } }