#include <iostream>
#include <cmath>
using namespace std;
inline bool is_palindrome(uint64_t n, uint64_t k)
{
if (n < 10 && k < 10)
return true;
int first_digit = n / k;
int last_digit = n % 10;
if (first_digit == last_digit)
return is_palindrome((n % k) / 10, k / 100);
else
return false;
}
inline uint64_t get_divider(uint64_t n)
{
uint64_t divider = 1;
while (n / divider >= 10){
divider *= 10;
}
return divider;
}
int main() {
int length = 3;
int max = std::pow(10, length) - 1;
int min = std::pow(10, length - 1) - 1;
//cout << max << ":" << min;
uint64_t max_palindrome = 0;
uint64_t n1, n2 = max;
for (uint64_t i = max; i > min; i--)
{
for (uint64_t j = max; j >= min; j--)
{
//cout << i << "*" << j << endl;
uint64_t number = i * j;
if (is_palindrome(number, get_divider(number)))
{
if (number > max_palindrome)
{
max_palindrome = number;
n1 = i;
n2 = j;
cout << n1 << "*" << n2 << "=" << max_palindrome <<endl;
}
}
}
}
cout << n1 << "*" << n2 << "=" << max_palindrome <<endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y21hdGg+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKCmlubGluZSBib29sIGlzX3BhbGluZHJvbWUodWludDY0X3QgbiwgdWludDY0X3QgaykKewoJaWYgKG4gPCAxMCAmJiBrIDwgMTApCgkJcmV0dXJuIHRydWU7CglpbnQgZmlyc3RfZGlnaXQgPSBuIC8gazsKCWludCBsYXN0X2RpZ2l0ID0gbiAlIDEwOwoJaWYgKGZpcnN0X2RpZ2l0ID09IGxhc3RfZGlnaXQpCgkJcmV0dXJuIGlzX3BhbGluZHJvbWUoKG4gJSBrKSAvIDEwLCBrIC8gMTAwKTsKCWVsc2UKCQlyZXR1cm4gZmFsc2U7Cn0KCmlubGluZSB1aW50NjRfdCBnZXRfZGl2aWRlcih1aW50NjRfdCBuKQp7Cgl1aW50NjRfdCBkaXZpZGVyID0gMTsKCXdoaWxlIChuIC8gZGl2aWRlciA+PSAxMCl7CgkJZGl2aWRlciAqPSA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