one-file-projects/euler3.c
2015-11-22 18:19:34 +01:00

24 lines
425 B
C

#include <stdio.h>
#include <math.h>
#include <assert.h>
long max(long a, long b) {
return a > b ? a : b;
}
long largest_prime_factor(long n) {
int p = 2;
while(n > 1) {
while(p < n && n%p!=0) p++;
while(n%p==0) n/=p;
}
return p;
}
int main( int argc, char *argv[] ) {
assert(largest_prime_factor(13195) == 29);
printf("%d\n",largest_prime_factor(600851475143));
return 0;
}