#include <iostream>
#include <vector>
#include <math.h>
bool is_palindrome(int num)
{
std::vector<int> split_num;
int max_exp = log10(num);
int current_num = num;
for (int e = max_exp; e >= 0; e--)
{
int power = (int)pow(10, e);
split_num.push_back(current_num / power);
current_num = current_num % power;
}
int length = split_num.size();
for (int i = 0; i < length / 2; i++)
if (split_num[i] != split_num[length - 1 - i])
return false;
return true;
}
int main() {
int max = 0;
for (int i = 1000; i <= 9999; i++)
for (int j = i; j <= 9999; j++) // wow! such optimization
{
int num = i * j;
if (is_palindrome(num))
if (num > max)
max = num;
}
std::cout << max;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8bWF0aC5oPgoKYm9vbCBpc19wYWxpbmRyb21lKGludCBudW0pCnsKCXN0ZDo6dmVjdG9yPGludD4gc3BsaXRfbnVtOwoJaW50IG1heF9leHAgPSBsb2cxMChudW0pOwoJaW50IGN1cnJlbnRfbnVtID0gbnVtOwoJZm9yIChpbnQgZSA9IG1heF9leHA7IGUgPj0gMDsgZS0tKQoJewoJCWludCBwb3dlciA9IChpbnQpcG93KDEwLCBlKTsKCQlzcGxpdF9udW0ucHVzaF9iYWNrKGN1cnJlbnRfbnVtIC8gcG93ZXIpOwoJCWN1cnJlbnRfbnVtID0gY3VycmVudF9udW0gJSBwb3dlcjsKCX0KCWludCBsZW5ndGggPSBzcGxpdF9udW0uc2l6ZSgpOwoJZm9yIChpbnQgaSA9IDA7IGkgPCBsZW5ndGggLyAyOyBpKyspCgkJaWYgKHNwbGl0X251bVtpXSAhPSBzcGxpdF9udW1bbGVuZ3RoIC0gMSAtIGldKQoJCQlyZXR1cm4gZmFsc2U7CglyZXR1cm4gdHJ1ZTsKfQoKaW50IG1haW4oKSB7CglpbnQgbWF4ID0gMDsKCWZvciAoaW50IGkgPSAxMDAwOyBpIDw9IDk5OTk7IGkrKykKCQlmb3IgKGludCBqID0gaTsgaiA8PSA5OTk5OyBqKyspIC8vIHdvdyEgc3VjaCBvcHRpbWl6YXRpb24KCQl7CgkJCWludCBudW0gPSBpICogajsKCQkJaWYgKGlzX3BhbGluZHJvbWUobnVtKSkKCQkJCWlmIChudW0gPiBtYXgpCgkJCQkJbWF4ID0gbnVtOwoJCX0KCXN0ZDo6Y291dCA8PCBtYXg7CglyZXR1cm4gMDsKfQ==