#include #include #include using namespace std; typedef unsigned long long ull; int main() { ull N, M; int ans = 0, times = 0; set recorder; cin >> N >> M; while (N != 0) { times++; if (times > 200) { cout << -1 << endl; return 0; } /* if (recorder.find(N) != recorder.end()) { cout << -1 << endl; return 0; } recorder.insert(N); */ string str = to_string(N / M); for (auto ch : str) { if (ch != '0') ans = ch - '0'; } N = (N % M) * 10; } cout << ans << endl; return 0; }