#include class inv { public: inv(long long n) : n(n), i(1) {} inv(const inv *other) : n(other->n), i(other->i) {} long long dig() { long long d = this->i / this->n; this->i = (this->i - d * this->n) * 10LL; return d; } bool eq(inv *other) const { return this->n == other->n && this->i == other->i; } private: long long n; long long i; }; bool is(long long n) { inv u(n); while (!u.dig()) { } inv v(u); for (;;) { if (!u.dig()) { return false; } if (!u.dig()) { return false; } v.dig(); if (u.eq(&v)) { return true; } } } int main() { int n = 0; for (long long v = 1; n < 10'000; v++) { if (is(v)) { std::cout << ++n << ' ' << v << std::endl; } } return 0; }