Blame view
07 - Primeros 10001 primos/p07.cpp
971 Bytes
5ec02016e p07: Resuelto, bu... |
1 2 3 4 5 6 7 8 9 10 11 |
/* 10001st prime Problem 7 By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13. What is the 10 001st prime number? by: dbk */ #include <stdio.h> |
382602797 p07: Reduccion co... |
12 |
#define SIZE_ARRAY 10001 |
5ec02016e p07: Resuelto, bu... |
13 14 15 16 17 18 19 20 |
int main(int argc, char const *argv[]) { int *ptrPrime; int numerador = 1; int denominador = 2; int arrayPrime[SIZE_ARRAY] = { 0 }; |
a70faf338 p07: Optimizando ... |
21 22 |
int counter = 0; int tmpCounter = 0; |
382602797 p07: Reduccion co... |
23 |
bool flgBuscar = true; |
5ec02016e p07: Resuelto, bu... |
24 25 26 |
do { |
382602797 p07: Reduccion co... |
27 |
flgBuscar = true; |
5ec02016e p07: Resuelto, bu... |
28 29 30 31 32 |
numerador = 1; ptrPrime = arrayPrime; do { |
382602797 p07: Reduccion co... |
33 |
while(*ptrPrime != 0 && flgBuscar) |
5ec02016e p07: Resuelto, bu... |
34 35 |
{ numerador = *ptrPrime; |
382602797 p07: Reduccion co... |
36 |
flgBuscar = !(denominador % *ptrPrime++ == 0); |
5ec02016e p07: Resuelto, bu... |
37 38 |
} |
382602797 p07: Reduccion co... |
39 |
if( denominador % numerador == 0 && denominador == numerador ) |
5ec02016e p07: Resuelto, bu... |
40 41 |
{ *ptrPrime = denominador; |
382602797 p07: Reduccion co... |
42 |
flgBuscar = false; |
a70faf338 p07: Optimizando ... |
43 |
counter++; |
382602797 p07: Reduccion co... |
44 |
|
5ec02016e p07: Resuelto, bu... |
45 |
} |
382602797 p07: Reduccion co... |
46 47 48 |
else numerador++; }while(flgBuscar); |
5ec02016e p07: Resuelto, bu... |
49 |
|
5ec02016e p07: Resuelto, bu... |
50 |
denominador++; |
a70faf338 p07: Optimizando ... |
51 |
|
9514fc1eb p07: Fix numeros ... |
52 |
} while (arrayPrime[SIZE_ARRAY-1] == 0); |
5ec02016e p07: Resuelto, bu... |
53 |
|
5ec02016e p07: Resuelto, bu... |
54 55 56 57 58 |
printf("El primo #%d es:\t%d ", SIZE_ARRAY, arrayPrime[SIZE_ARRAY-1]); return 0; } |