From 506f390293f6497dbb3e38031a92e018de3403f8 Mon Sep 17 00:00:00 2001 From: Kai Stevenson Date: Fri, 31 Mar 2023 23:06:23 -0700 Subject: init --- problem3/problem3.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 problem3/problem3.c (limited to 'problem3/problem3.c') 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 + +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; + } + } +} -- cgit v1.2.3-70-g09d2