#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; unsigned long long int gcd(unsigned long long int a, unsigned long long int b) { if (b == 0) { return a; } return gcd(b, a % b); } int main(void) { cin.tie(0); ios::sync_with_stdio(false); unsigned long long int N, M; cin >> N >> M; unsigned long long int g = gcd(N, M); N /= g; M /= g; unsigned long long int temp = M; while (1) { if (temp % 2 != 0) { break; } temp /= 2; } while (1) { if (temp % 5 != 0) { break; } temp /= 5; } if (temp > 1) { cout << -1 << '\n'; return 0; } unsigned long long int res = 0; unsigned long long int XX = N / M; while (XX > 0) { if (XX % 10 != 0) { res = XX % 10; break; } XX /= 10; } N %= M; while (1) { if (N == 0) { break; } N *= 10; unsigned long long int a = N / M; N %= M; //cout << N << ' ' << a << '\n'; res = a; } cout << res << '\n'; return 0; }