summaryrefslogtreecommitdiff
path: root/problem3/problem3.c
diff options
context:
space:
mode:
Diffstat (limited to 'problem3/problem3.c')
-rw-r--r--problem3/problem3.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/problem3/problem3.c b/problem3/problem3.c
new file mode 100644
index 0000000..9b9756c
--- /dev/null
+++ b/problem3/problem3.c
@@ -0,0 +1,25 @@
+/*
+ The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ?
+*/
+
+#include <stdio.h>
+
+char is_prime(unsigned long long int n) {
+ for (unsigned long long int i = 2; i < n; i++) {
+ if (n % i == 0) {
+ return 0;
+ }
+ }
+ return 1;
+}
+
+int main() {
+ unsigned long long int c = 600851475143;
+ for (unsigned long long int i = c / 2; i--; i >= 0) {
+ printf("%llu\n", i);
+ if (is_prime(i)) {
+ printf("%llu\n", i);
+ break;
+ }
+ }
+}