#include using namespace std; using lint = long long; using pint = pair; using plint = pair; #define ALL(x) (x).begin(), (x).end() #define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i=i##_begin_;i--) #define REP(i, n) FOR(i,0,n) #define IREP(i, n) IFOR(i,0,n) template void ndarray(vector &vec, int len) { vec.resize(len); } template void ndarray(vector &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); } template void ndfill(V &x, const T &val) { x = val; } template void ndfill(vector &vec, const T &val) { for (auto &v : vec) ndfill(v, val); } template bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; } template bool chmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; } template pair operator+(const pair &l, const pair &r) { return make_pair(l.first + r.first, l.second + r.second); } template pair operator-(const pair &l, const pair &r) { return make_pair(l.first - r.first, l.second - r.second); } template vector srtunq(vector vec) { sort(vec.begin(), vec.end()), vec.erase(unique(vec.begin(), vec.end()), vec.end()); return vec; } template istream &operator>>(istream &is, vector &vec) { for (auto &v : vec) is >> v; return is; } template istream &operator>>(istream &is, tuple &tpl) { std::apply([&is](auto &&... args) { ((is >> args), ...);}, tpl); return is; } template ostream &operator<<(ostream &os, const vector &vec) { os << '['; for (auto v : vec) os << v << ','; os << ']'; return os; } template ostream &operator<<(ostream &os, const tuple &tpl) { std::apply([&os](auto &&... args) { ((os << args << ','), ...);}, tpl); return os; } template ostream &operator<<(ostream &os, const deque &vec) { os << "deq["; for (auto v : vec) os << v << ','; os << ']'; return os; } template ostream &operator<<(ostream &os, const set &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; } template ostream &operator<<(ostream &os, const unordered_set &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; } template ostream &operator<<(ostream &os, const multiset &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; } template ostream &operator<<(ostream &os, const unordered_multiset &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; } template ostream &operator<<(ostream &os, const pair &pa) { os << '(' << pa.first << ',' << pa.second << ')'; return os; } template ostream &operator<<(ostream &os, const map &mp) { os << '{'; for (auto v : mp) os << v.first << "=>" << v.second << ','; os << '}'; return os; } template ostream &operator<<(ostream &os, const unordered_map &mp) { os << '{'; for (auto v : mp) os << v.first << "=>" << v.second << ','; os << '}'; return os; } #define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl; pint fac(lint x) { int i2 = 0, i5 = 0; while (x % 2 == 0) x /= 2, i2++; while (x % 5 == 0) x /= 5, i5++; return pint(i2, i5); } lint val(pint p) { lint ret = 1; REP(_, p.first) ret *= 2; REP(_, p.second) ret *= 5; return ret; } int main() { lint x1, x2; cin >> x1 >> x2; pint p1 = fac(x1), p2 = fac(x2); while (true) { if (p1 == p2) return 0; int dist = abs(p1.first - p2.first) + abs(p1.second - p2.second); if (dist == 1) p1 = p2; else if (dist % 2 == 0) { if (p1 == pint(9, 9)) p1 = pint(7, 9); else if (p1 == pint(7, 9)) p1 = pint(9, 9); else if (p1.second < 9) p1.second++; else if (p1.first == 8) p1.first--; else p1.first++; } else { if (p1.first <= p2.first and p1.first < 9) p1.first++; else if (p1.second <= p2.second and p1.second < 9) p1.second++; else if (p1.first - 1 > p2.first) p1.first--; else if (p1.second - 1 > p2.second) p1.second--; else exit(8); } cout << val(p1) << endl; if (p1 == p2) return 0; lint x; cin >> x; p2 = fac(x); } }