#include <bits/stdc++.h>
using namespace std;
const int MAXN = 25005;
long long f[MAXN], sg[MAXN]; int p;
int qkpow(int a, int b) {
int ans = 1; for (; b; b >>= 1, a = 1ll * a * a % p) if (b & 1) ans = 1ll * ans * a % p; return ans;
}
int main() {
int t; scanf("%d %d", &t, &p);
f[0] = 1; f[1] = 1; for (int i = 1; i <= 23333; i++) sg[i]++;
for (int i = 2; i <= 23333; i++) {
__int128 tmpf = 0; for (int j = 0; j < i; j++) tmpf += (__int128)f[j] * sg[i - j];
f[i] = tmpf % p * qkpow(i, p - 2) * 2 % p; long long tmpg = tmpf % p;
for (int j = i; j <= 23333; j += i) sg[j] += tmpg;
}
while (t--) {int n; scanf("%d", &n); printf("%d\n", (int)f[n]);}
}