1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 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; }