Skip to content
Extraits de code Groupes Projets
Valider da36e62c rédigé par Romain Lefèbvre's avatar Romain Lefèbvre
Parcourir les fichiers

fonction de prime facto la plus rapide des 3.

parent 11055c44
Branches rom
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
# include <stdio.h>
#include <math.h>
#include <sys/time.h>
// A function to print all prime factors of a given number n
# include <stdio.h>
# include <math.h>
// A function to print all prime factors of a given number n
void primeFactors(int n)
{
int count1=0;
int count2=0;
while (n%2 == 0)
{
if(count1==0) printf("%d ", 2);
n = n/2;
count1+=1;
}
for (int i = 3; i <= sqrt(n); i = i+2)
{
while (n%i == 0)
{
if(count2==0) printf("%d ", i);
n=n/i;
count2+=1;
}
count2=0;
}
if (n > 2)
printf ("%d ", n);
}
/* Driver program to test above function */
int main() {
struct timeval stop, start;
gettimeofday(&start, NULL);
int n = 666343;
primeFactors(n);
printf("\n");
int b = 463698;
primeFactors(b);
printf("\n");
int c = 1021406;
primeFactors(c);
printf("\n");
int d = 506156;
primeFactors(d);
printf("\n");
int e = 913231;
primeFactors(e);
printf("\n");
int f = 268205;
primeFactors(f);
printf("\n");
int g = 982865;
primeFactors(g);
printf("\n");
int h = 917451;
primeFactors(h);
printf("\n");
gettimeofday(&stop, NULL);
printf("%lu", (stop.tv_sec - start.tv_sec) * 1000000 + stop.tv_usec - start.tv_usec);
return 0;
}
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter