diff --git a/main.c b/main.c new file mode 100644 index 0000000000000000000000000000000000000000..7f87cf68d9935f522d583ac9aae885a6dc8eb7e2 --- /dev/null +++ b/main.c @@ -0,0 +1,75 @@ +# 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; +} + + + + + + + +