#include #pragma GCC optmzied(fast) #define forn(i,s,t) for(register int i=(s); i<=(t); ++i) #define forl(i,s,t) for(register i64 i=(s); i<=(t); ++i) #define form(i,s,t) for(register int i=(s); i>=(t); --i) #define rep(i,s,t) for(register int i=(s); i<(t); ++i) #define IT(u) for(register int i=G[u]; i; i=E[i].nxt) using namespace std; namespace FASTIO { const int SIZ = 1 << 27 | 1; char ibuf[SIZ], obuf[SIZ], *iS = ibuf, *iT = ibuf, *oS = obuf, *oT = obuf + SIZ - 1, qwq[60], qaq; #define gc() (iS == iT && (iT = (iS = ibuf) + fread(ibuf, 1, SIZ, stdin), iS == iT) ? EOF : *iS++) template inline void Rdn(T& A) { register bool fl = 0; register char ch = gc(); A = 0; while(!isdigit(ch)) fl = (ch == '-'), ch = gc(); while(isdigit(ch)) A = (A * 10) + (ch & 15), ch = gc(); fl && (A = -A); } inline void Rdn(char& c) {while((c = gc()) == ' ' || c == '\n' || c == '\r');} inline void Rdn(char* s) { while((*s = gc()) == ' ' || *s == '\n' || *s == '\r') ; if(*s == EOF) return ; while(*s != ' ' && *s != '\n' && *s != '\r' && *s != EOF) *(++s) = gc(); *s = 0; } template inline void Rdn(T& A, U& ...B) {Rdn(A), Rdn(B...);} inline void flush() {fwrite(obuf, 1, oS - obuf, stdout), oS = obuf;} inline void pc(char c) {*oS ++ = c; if(oS == oT) flush();} template inline void Wtn(T A) { if(!A) return pc('0'); if(A < 0) pc('-'), A = -A; while(A) qwq[++qaq] = A % 10 + '0', A /= 10; while(qaq) pc(qwq[qaq -- ]); } inline void Wtn(char A) {pc(A);} inline void Wtn(char *s) {while(*s) pc(*s), ++s;} inline void Wtn(const char *s) {while(*s) pc(*s), ++s;} template inline void Wtn(T A, U ...B) {Wtn(A), Wtn(B...);} #undef gc } using FASTIO :: Rdn; using FASTIO :: Wtn; using FASTIO :: flush; typedef long long i64; typedef double f64; typedef unsigned long long u64; typedef pair pii; typedef pair piu; const int N = 1e7 + 5; const i64 INF = 1e18; inline void init() {} int K, Q; i64 n, X[N], F[N], num; inline i64 CiL(i64 A, i64 B) { return A / B + !!(A % B); } inline void solve() { Rdn(K, Q); X[++num] = 1, F[num] = 1; while (X[num] < 1e18) X[num + 1] = X[num] + CiL(X[num], K - 1), ++num, F[num] = F[num - 1] + CiL(F[num - 1], K - 1); while (Q--) { Rdn(n); Wtn(F[upper_bound(X + 1, X + num + 1, n) - X - 1], '\n'); } } int Trd; int main() { Trd = 1; while(Trd--) init(), solve(); flush(); return 0; }