#pragma GCC optimize ("Ofast") #pragma GCC optimize ("unroll-loops") #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; using Int = long long; template ostream &operator<<(ostream &os, const pair &a) { return os << "(" << a.first << ", " << a.second << ")"; }; template void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; } template bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; } template bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; } int main() { unsigned long long K; int Q; scanf("%llu%d", &K, &Q); --K; const unsigned __int128 invK = ~0ULL / K + 1; if (K == 1) { for (; Q--; ) { unsigned long long N; scanf("%llu", &N); unsigned long long x = 0; for (; ; ) { const unsigned long long xx = x + x + 1; if (xx >= N) { break; } x = xx; } printf("%lld\n", x + 1); } } else { for (; Q--; ) { unsigned long long N; scanf("%llu", &N); if (N <= K + 1) { printf("%llu\n", N); } else { unsigned long long x = K; for (; ; ) { const unsigned long long y = (invK * x) >> 64; const unsigned long long xx = x + y + (K * y <= x); if (xx >= N) { break; } x = xx; } printf("%lld\n", x + 1); } } } return 0; }