aboutsummaryrefslogtreecommitdiffstats
path: root/03-Largest-Prime-Factor
diff options
context:
space:
mode:
Diffstat (limited to '03-Largest-Prime-Factor')
-rwxr-xr-x03-Largest-Prime-Factor/largestprimebin0 -> 16648 bytes
-rw-r--r--03-Largest-Prime-Factor/largestprime.c21
-rw-r--r--03-Largest-Prime-Factor/largestprime.py16
3 files changed, 37 insertions, 0 deletions
diff --git a/03-Largest-Prime-Factor/largestprime b/03-Largest-Prime-Factor/largestprime
new file mode 100755
index 0000000..c2afe6f
--- /dev/null
+++ b/03-Largest-Prime-Factor/largestprime
Binary files differ
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)