boolisPalindrome(string str){ for (int i = 0, j = str.size() - 1; i < j; ++i, --j) { if (str[i] != str[j]) returnfalse; }
returntrue; }
stringgetNumber(int number, int BASE, constvector<int> &table){ string str; int base = BASE; while (number) { int digit = number % base; int factor = base / BASE; digit /= factor; str.push_back(table[digit]); number -= digit * factor; base *= BASE; }
int BASE; fin >> BASE; for (int i = 1; i <= 300; ++i) { string num = getNumber(i * i, BASE, table); if (isPalindrome(num)) { fout << getNumber(i, BASE, table) << " "; fout << num << std::endl; } }