diff options
Diffstat (limited to 'largestprime.c')
-rw-r--r-- | largestprime.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/largestprime.c b/largestprime.c new file mode 100644 index 0000000..bf98414 --- /dev/null +++ b/largestprime.c @@ -0,0 +1,21 @@ +#include <stdio.h> +#include <stdlib.h> + +long lpf(long num){ + long factor = 2; + while(num > factor){ + if(num % factor == 0){ + num = num / factor; + factor = 2; + } + else{ + factor ++; + } + } + return factor; +} + +int main(){ + printf("%d\n", lpf(600851475143)); + return 0; +} |