aboutsummaryrefslogtreecommitdiffstats
path: root/03-Largest-Prime-Factor/largestprime.c
blob: bf98414f6d5261ea6d09f6f56930d921f00b1335 (plain)
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;
}