Project Euler Problem 3

Problem 3 - Project Euler

コード

#include <cstdio>

long long lpf(long long x){
	long long maximum = 0;
	while(x != 1){
		for(long long i = 2; ; i++){
			if(!(x % i)){
				x /= i;
				maximum = i;
				break;
			}
		}
	}

	return maximum;
}
int main()
{
	printf("%lld\n", lpf(600851475143));
	return 0;
}

答え

6857