diff options
Diffstat (limited to '03-Largest-Prime-Factor')
-rwxr-xr-x | 03-Largest-Prime-Factor/largestprime | bin | 0 -> 16648 bytes | |||
-rw-r--r-- | 03-Largest-Prime-Factor/largestprime.c | 21 | ||||
-rw-r--r-- | 03-Largest-Prime-Factor/largestprime.py | 16 |
3 files changed, 37 insertions, 0 deletions
diff --git a/03-Largest-Prime-Factor/largestprime b/03-Largest-Prime-Factor/largestprime Binary files differnew file mode 100755 index 0000000..c2afe6f --- /dev/null +++ b/03-Largest-Prime-Factor/largestprime diff --git a/03-Largest-Prime-Factor/largestprime.c b/03-Largest-Prime-Factor/largestprime.c new file mode 100644 index 0000000..bf98414 --- /dev/null +++ b/03-Largest-Prime-Factor/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; +} diff --git a/03-Largest-Prime-Factor/largestprime.py b/03-Largest-Prime-Factor/largestprime.py new file mode 100644 index 0000000..387de01 --- /dev/null +++ b/03-Largest-Prime-Factor/largestprime.py @@ -0,0 +1,16 @@ +import PIL +import math +# Problem 3 Largest Prime Factor +def lpf(number): + factor = 2 + while (number > factor): + if(number % factor == 0): + number = number/factor + factor = 2 + else: + factor += 1 + return factor + + +out = lpf(600851475143) +print(out) |