/* Check cf5-opt.vim defs.
VIM: let g:lcppflags="-std=c++11 -O2 -pthread"
VIM: let g:wcppflags="/O2 /EHsc /DWIN32"
*/
#include <iostream>

/*
Largest prime factor
Problem 3
The prime factors of 13195 are 5, 7, 13 and 29.

What is the largest prime factor of the number 600851475143 ?

Solution:
6857
*/

long long max_factor( long long n )
{
	long long h = (long long)sqrt(double(n));
	for ( long long i = 2; i <= h; )
		if ( n%i )
			++i;
		else
		{
			n/=i;
			h = (long long)sqrt(double(n));
			//std::cout << "prime " << i << " " << n << std::endl;
		}
	//std::cout << "prime " << n << " 1" << std::endl;
	return n;
}

int main ( void )
{
	const long long n = 600851475143;
	std::cout << max_factor( n ) << std::endl;

	return 0;
}

