diff --git a/palindrome-number/main.cc b/palindrome-number/main.cc new file mode 100644 index 0000000..bf78f2c --- /dev/null +++ b/palindrome-number/main.cc @@ -0,0 +1,29 @@ +#include +#include +using namespace std; + +string dec2oct(int dec) { + string buffer; + while (dec) { + buffer = char(dec % 8 + '0') + buffer; + dec /= 8; + } + return buffer; +} + +bool is_palindrome_number(string val) { + string reversed; + for (int i = val.size() - 1; i >= 0; i--) + reversed += val[i]; + return reversed == val; +} + +int main() { + int n; + cin >> n; + int sqaure_n = sqrt(n); + for (int i = 1; i <= sqaure_n; i++) { + if (is_palindrome_number(dec2oct(i * i))) + cout << i * i << " "; + } +}