aboutsummaryrefslogtreecommitdiffstats
path: root/largestprime.c
diff options
context:
space:
mode:
authormjf <mjf@localhost.localdomain>2020-02-04 12:11:30 -0500
committermjf <mjf@localhost.localdomain>2020-02-04 12:11:30 -0500
commit6aa02212cd6dfbb492fa1f70b60a4fe3d48892e5 (patch)
tree1b655714c9709ee8fce333fcb6a6be3f5533b2d3 /largestprime.c
parent8e431d287c0e89041506da4c4da57e3e3d657d72 (diff)
downloadProject_Euler_Solutions-6aa02212cd6dfbb492fa1f70b60a4fe3d48892e5.tar.gz
cleanup and added more c examples:
Diffstat (limited to 'largestprime.c')
-rw-r--r--largestprime.c21
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;
+}