#include #include using namespace std; using atcoder::modint; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N, E; cin >> N >> E; if (E == 0) { cout << "0\n"; return 0; } int mod = 1; modint ::set_mod(mod); modint ans = 0; while (E--) { modint::set_mod(mod * 5); int r = ans.val(); bool found = false; for (int i = 0; i < 5; ++i) { auto x = modint(r + i * mod); if (x * x == N) { ans = x; found = true; break; } } if (!found) { cout << "NaN\n"; return 0; } mod *= 5; } for (int i = 0; i < 5; ++i) { for (int e : {(ans + mod / 5 * i).val(), (-ans + mod / 5 * i).val() - mod}) { if (-(1 << 29) <= e && e <= 1 << 29) { cout << e << '\n'; return 0; } } } cout << "NaN\n"; }