aboutsummaryrefslogtreecommitdiffstats
path: root/03-Largest-Prime-Factor/largestprime.c
diff options
context:
space:
mode:
authormjfernez <mjfernez@gmail.com>2020-02-09 15:16:26 -0500
committermjfernez <mjfernez@gmail.com>2020-02-09 15:16:26 -0500
commit93ea7fe5957b62f18e8fbd17a21696bd7de6332d (patch)
treed90aed60d687bcf195f1150777f37cbe8a149814 /03-Largest-Prime-Factor/largestprime.c
parent125ec5bc3d8bfc224b7d32bcfbbc37b9fb5d441f (diff)
downloadProject_Euler_Solutions-93ea7fe5957b62f18e8fbd17a21696bd7de6332d.tar.gz
Organized everything, update README
Diffstat (limited to '03-Largest-Prime-Factor/largestprime.c')
-rw-r--r--03-Largest-Prime-Factor/largestprime.c21
1 files changed, 21 insertions, 0 deletions
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;
+}