-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3.c
More file actions
27 lines (22 loc) · 643 Bytes
/
3.c
File metadata and controls
27 lines (22 loc) · 643 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/*
The prime factors of 13195 are 5, 7, 13 and 29.
What is the largest prime factor of the number 600851475143 ?
*/
#include <stdio.h>
#include <math.h>
#include <locale.h>
#include "isprime.h"
int main(void) {
unsigned long long int num = 600851475143;
unsigned long long int half = floor(num / 2);
setlocale(LC_NUMERIC, "");
printf("half: %'llu\n", half);
// loop through all numbers up to half of num
// if number is_prime and factors num, print
for(unsigned long long int i = 1; i <= half; i += 2) {
if(is_prime(i) && num % i == 0) {
printf("%llu\n", i);
}
}
return 0;
}