Skip to content

Instantly share code, notes, and snippets.

@yamishi13
Created November 25, 2014 19:00
Show Gist options
  • Save yamishi13/8e15d31aa03753ad1284 to your computer and use it in GitHub Desktop.
Save yamishi13/8e15d31aa03753ad1284 to your computer and use it in GitHub Desktop.
paralell primos
#include <stdio.h>
#include <time.h>
const int NUMPRIMOS = 1000000;
clock_t start,end;
int CalculaPrimosFuerzaBruta()
{
int candidato;
bool esprimo;
int cuantosprimos = 0;
for(candidato = 2;candidato < NUMPRIMOS;candidato++)
{
esprimo = true;
for(int j = 2;j < candidato;j++)
{
if((candidato % j) == 0)
{
esprimo = false;
j = candidato;
}
}
if(esprimo)
cuantosprimos++;
// printf("%d\t",candidato);
}
return cuantosprimos;
}
int main(int argc, char** argv)
{
double time_in_seconds;
int cuantosprimos;
start=clock();
cuantosprimos = CalculaPrimosFuerzaBruta();
end=clock();
time_in_seconds=(double)(end-start)/(double)CLOCKS_PER_SEC;
printf("encontro %d numeros primos en %g segundos",cuantosprimos,time_in_seconds);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment