#include <iostream>
#include <cmath>
unsigned largest_prime_factor(unsigned n)
{
unsigned lpf = 0;
unsigned stop = sqrt(n);
for (unsigned i=2; i<=stop; ++i)
if (n%i==0) {
lpf = i;
while (n%i==0) { n/= i; }
stop = sqrt(n);
}
return n==1 ? lpf : n;
}
int main()
{
std::cout << largest_prime_factor(2147483647) << "\n";
std::cout << largest_prime_factor(4294967291) << "\n";
std::cout << largest_prime_factor(4294967294) << "\n";
std::cout << largest_prime_factor(65536) << "\n";
std::cout << largest_prime_factor(2*2*2*7*13*19) << "\n";
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y21hdGg+Cgp1bnNpZ25lZCBsYXJnZXN0X3ByaW1lX2ZhY3Rvcih1bnNpZ25lZCBuKQp7CiAgICB1bnNpZ25lZCBscGYgPSAwOwogICAgdW5zaWduZWQgc3RvcCA9IHNxcnQobik7CiAgICBmb3IgKHVuc2lnbmVkIGk9MjsgaTw9c3RvcDsgKytpKQogICAgICAgIGlmIChuJWk9PTApIHsKICAgICAgICAgICAgbHBmID0gaTsKICAgICAgICAgICAgd2hpbGUgKG4laT09MCkgeyBuLz0gaTsgfQogICAgICAgICAgICBzdG9wID0gc3FydChuKTsKICAgICAgICB9CiAgICByZXR1cm4gbj09MSA/IGxwZiA6IG47Cn0KCmludCBtYWluKCkKewogICAgc3RkOjpjb3V0IDw8IGxhcmdlc3RfcHJpbWVfZmFjdG9yKDIxNDc0ODM2NDcpIDw8ICJcbiI7CiAgICBzdGQ6OmNvdXQgPDwgbGFyZ2VzdF9wcmltZV9mYWN0b3IoNDI5NDk2NzI5MSkgPDwgIlxuIjsKICAgIHN0ZDo6Y291dCA8PCBsYXJnZXN0X3ByaW1lX2ZhY3Rvcig0Mjk0OTY3Mjk0KSA8PCAiXG4iOwogICAgc3RkOjpjb3V0IDw8IGxhcmdlc3RfcHJpbWVfZmFjdG9yKDY1NTM2KSA8PCAiXG4iOwogICAgc3RkOjpjb3V0IDw8IGxhcmdlc3RfcHJpbWVfZmFjdG9yKDIqMioyKjcqMTMqMTkpIDw8ICJcbiI7Cn0=