#include <bits/stdc++.h>

#define int long long

using namespace std;

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int k, q;
    cin >> k >> q;
    const int maxN = 15005;
    const int maxK = 1005;
    double old[maxK]; // dp[days][balls] = probability.
    for (int j = 0; j < maxK; j++) old[j] = 0;
    old[0] = 1;
    double record[maxN];
    for (int i = 0; i < maxN; i++) record[i] = 0;
    for (int i = 0; i < maxN-5; i++) {
        record[i] = old[k];
        double dp[maxK];
        for (int j = 0; j < maxK; j++) dp[j] = 0;
        for (int j = 0; j < maxK-5; j++) {
            dp[j] += old[j]*((double)j/(double)k);
            dp[j+1] += old[j]*((double)(k-j)/(double)k);
        }
        for (int j = 0; j < maxK; j++) old[j] = dp[j];
    }
    double eps = 1e-7;
    for (int i = 0; i < q; i++) {
        double p;
        cin >> p;
        for (int j = 0; j < maxN; j++) {
            if (record[j] > (p-eps)/2000) {
                cout << j << '\n';
                break;
            }
        }
    }
}
/*

 */


#include <bits/stdc++.h>

#define int long long

using namespace std;

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int k, q;
    cin >> k >> q;
    const int maxn = 1005;
    double dp[maxn][maxn]; // dp[days][balls] = probability.
    for (int i = 0; i < maxn; i++) for (int j = 0; j < maxn; j++) dp[i][j] = 0;
    dp[0][0] = 1;
    for (int i = 0; i < maxn-5; i++) {
        for (int j = 0; j < maxn-5; j++) {
            dp[i+1][j] += dp[i][j]*((double)j/(double)k);
            dp[i+1][j+1] += dp[i][j]*((double)(k-j)/(double)k);
        }
    }
    double eps = 1e-7;
    for (int i = 0; i < q; i++) {
        double p;
        cin >> p;
        for (int j = 0; j < maxn; j++) {
            if (dp[j][k] > (p-eps)/2000) {
                cout << j << '\n';
                break;
            }
        }
    }
}
/*

 */


#include <bits/stdc++.h>

#define int long long

using namespace std;

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int k, q;
    cin >> k >> q;
    const int maxN = 15005;
    const int maxK = 1005;
    double dp[maxN][maxK]; // dp[days][balls] = probability.
    for (int i = 0; i < maxN; i++) for (int j = 0; j < maxK; j++) dp[i][j] = 0;
    dp[0][0] = 1;
    for (int i = 0; i < maxN-1; i++) {
        for (int j = 0; j < maxK-1; j++) {
            dp[i+1][j] += dp[i][j]*((double)j/(double)k);
            dp[i+1][j+1] += dp[i][j]*((double)(k-j)/(double)k);
        }
    }
    double eps = 1e-7;
    for (int i = 0; i < q; i++) {
        double p;
        cin >> p;
        for (int j = 0; j < maxN; j++) {
            if (dp[j][k]*2000 >= (p-eps)) {
                cout << j << '\n';
                break;
            }
        }
    }
}
/*

 */


#include <bits/stdc++.h>

#define int long long

using namespace std;

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int k, q;
    cin >> k >> q;
    const int maxN = 30005;
    const int maxK = 1005;
    double dp[maxN][maxK]; // dp[days][balls] = probability.
    for (int i = 0; i < maxN; i++) for (int j = 0; j < maxK; j++) dp[i][j] = 0;
    dp[0][0] = 1;
    for (int i = 0; i < maxN-5; i++) {
        for (int j = 0; j < maxK-5; j++) {
            dp[i+1][j] += dp[i][j]*((double)j/(double)k);
            dp[i+1][j+1] += dp[i][j]*((double)(k-j)/(double)k);
        }
    }
    double eps = 1e-7;
    for (int i = 0; i < q; i++) {
        double p;
        cin >> p;
        for (int j = 0; j < maxN; j++) {
            if (dp[j][k] > (p-eps)/2000) {
                cout << j << '\n';
                break;
            }
        }
    }
}
/*

 */


#include <bits/stdc++.h>

#define int long long

using namespace std;

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int k, q;
    cin >> k >> q;
    const int maxN = 15005;
    const int maxK = 1005;
    double dp[maxN][maxK]; // dp[days][balls] = probability.
    for (int i = 0; i < maxN; i++) for (int j = 0; j < maxK; j++) dp[i][j] = 0;
    dp[0][0] = 1;
    for (int i = 0; i < maxN-5; i++) {
        for (int j = 0; j < maxK-5; j++) {
            dp[i+1][j] += dp[i][j]*((double)j/(double)k);
            dp[i+1][j+1] += dp[i][j]*((double)(k-j)/(double)k);
        }
    }
    double eps = 1e-7;
    for (int i = 0; i < q; i++) {
        double p;
        cin >> p;
        for (int j = 0; j < maxN; j++) {
            if (dp[j][k] > (p-eps)/2000) {
                cout << j << '\n';
                break;
            }
        }
    }
}
/*

 */


#include <bits/stdc++.h>

#define int long long

using namespace std;

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int k, q;
    cin >> k >> q;
    const int maxN = 15005;
    const int maxK = 1005;
    double dp[maxN][maxK]; // dp[days][balls] = probability.
    for (int i = 0; i < maxN; i++) for (int j = 0; j < maxK; j++) dp[i][j] = 0;
    dp[0][0] = 1;
    for (int i = 0; i < maxN-5; i++) {
        for (int j = 0; j < maxK-5; j++) {
            dp[i+1][j] += dp[i][j]*((double)j/(double)k);
            dp[i+1][j+1] += dp[i][j]*((double)(k-j)/(double)k);
        }
    }
    double eps = 1e-7;
    for (int i = 0; i < q; i++) {
        double p;
        cin >> p;
        for (int j = 0; j < maxN; j++) {
            if (dp[j][k]*2000 >= (p-eps)) {
                cout << j << '\n';
                break;
            }
        }
    }
}
/*

 */


#include <bits/stdc++.h>

#define int long long

using namespace std;

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int k, q;
    cin >> k >> q;
    const int maxn = 2005;
    double dp[maxn][maxn]; // dp[days][balls] = probability.
    for (int i = 0; i < maxn; i++) for (int j = 0; j < maxn; j++) dp[i][j] = 0;
    dp[0][0] = 1;
    for (int i = 0; i < maxn-5; i++) {
        for (int j = 0; j < maxn-5; j++) {
            dp[i+1][j] += dp[i][j]*((double)j/(double)k);
            dp[i+1][j+1] += dp[i][j]*((double)(k-j)/(double)k);
        }
    }
    double eps = 1e-7;
    for (int i = 0; i < q; i++) {
        double p;
        cin >> p;
        for (int j = 0; j < maxn; j++) {
            if (dp[j][k] > (p-eps)/2000) {
                cout << j << '\n';
                break;
            }
        }
    }
}
/*

 */


#include <bits/stdc++.h>

#define int long long

using namespace std;

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int k, q;
    cin >> k >> q;
    const int maxN = 20005;
    const int maxK = 1005;
    double dp[maxN][maxK]; // dp[days][balls] = probability.
    for (int i = 0; i < maxN; i++) for (int j = 0; j < maxK; j++) dp[i][j] = 0;
    dp[0][0] = 1;
    for (int i = 0; i < maxN-5; i++) {
        for (int j = 0; j < maxK-5; j++) {
            dp[i+1][j] += dp[i][j]*((double)j/(double)k);
            dp[i+1][j+1] += dp[i][j]*((double)(k-j)/(double)k);
        }
    }
    double eps = 1e-7;
    for (int i = 0; i < q; i++) {
        double p;
        cin >> p;
        for (int j = 0; j < maxN; j++) {
            if (dp[j][k] > (p-eps)/2000) {
                cout << j << '\n';
                break;
            }
        }
    }
}
/*

 */


#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pair<int,int>>
#define vpll vector<pair<ll,ll>>
#define fr(i,k,n) for (int i = k; i < n; ++i)
#define fri(i,k,n) for (int i = k; i >= n; --i)
#define pb push_back
#define mp make_pair
#define all(arr) arr.begin(),arr.end()
#define ff first
#define ss second

const double pi=3.1415926535897932384626433832795;
const int inf=1e9;
const ll inf2=1e18;
const int mod=1e9+7;
const ld eps=1e-8;

void boost(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

void solve(){
    int k,q;
    cin>>k>>q;
    vector<ld> dp(k+1,0);
    vi ans(1002);
    dp[0]=1;
    int x=1;
    for(int i=1;x<1001;i++){
        for(int j=k;j>0;j--){
            dp[j]=(1.0*k*dp[j] + (k-j+1)*1.0*dp[j-1])/(1.0*k);
        }
        dp[0]=0;
        while(x<=1000 && 2000*1.0*dp[k]>=(x-eps)){
            ans[x]=i;
            x++;
        }
    }
    while(q--){
        cin>>x;
        cout<<ans[x]<<endl;
    }
    return;
}

int main()
{
    boost();

    int tc=1;
    //cin>>tc;
    while(tc--)
        solve();
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pair<int,int>>
#define vpll vector<pair<ll,ll>>
#define fr(i,k,n) for (int i = k; i < n; ++i)
#define fri(i,k,n) for (int i = k; i >= n; --i)
#define pb push_back
#define mp make_pair
#define all(arr) arr.begin(),arr.end()
#define ff first
#define ss second

const double pi=3.1415926535897932384626433832795;
const int inf=1e9;
const ll inf2=1e18;
const int mod=1e9+7;
const ld eps=1e-7;

void boost(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

void solve(){
    int k,q;
    cin>>k>>q;
    vector<ld> dp(k+1,0);
    vi ans(1002);
    dp[0]=1;
    int x=1;
    for(int i=1;x<1001;i++){
        for(int j=k;j>0;j--){
            dp[j]=(j*dp[j] + (k-j+1)*dp[j-1])/(1.0*k);
            // cout<<dp[j]<<" ";
        }
        // cout<<endl;
        dp[0]=0;
        while(x<=1000 && 2000*1.0*dp[k]>=(x-eps)){
            ans[x]=i;
            x++;
        }
    }
    while(q--){
        cin>>x;
        cout<<ans[x]<<endl;
    }
    return;
}

int main()
{
    boost();

    int tc=1;
    //cin>>tc;
    while(tc--)
        solve();
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pair<int,int>>
#define vpll vector<pair<ll,ll>>
#define fr(i,k,n) for (int i = k; i < n; ++i)
#define fri(i,k,n) for (int i = k; i >= n; --i)
#define pb push_back
#define mp make_pair
#define all(arr) arr.begin(),arr.end()
#define ff first
#define ss second

const double pi=3.1415926535897932384626433832795;
const int inf=1e9;
const ll inf2=1e18;
const int mod=1e9+7;
const ld eps=1e-7;

void boost(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

void solve(){
    int k,q;
    cin>>k>>q;
    vector<ld> dp(k+1,0);
    vi ans(1002);
    dp[0]=1;
    int x=1;
    for(int i=1;x<1001;i++){
        for(int j=k;j>0;j--){
            dp[j]=(1.0*k*dp[j] + (k-j+1)*1.0*dp[j-1])/(1.0*k);
        }
        dp[0]=0;
        while(x<=1000 && 2000*1.0*dp[k]>=(x-eps)){
            ans[x]=i;
            x++;
        }
    }
    while(q--){
        cin>>x;
        cout<<ans[x]<<endl;
    }
    return;
}

int main()
{
    boost();

    int tc=1;
    //cin>>tc;
    while(tc--)
        solve();
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(), (x).end()
#define int long long
const int N = 2000;
double dp[N];
int ans[N];
signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int k, q;
    cin >> k >> q;
    int cur = 1;
    dp[0] = 1;
    for (int n = 1; n <= 1000; ++n) {
        for (int x = k; x > 0; --x) {
            dp[x] = (x * dp[x] + (k - x + 1) * dp[x - 1]) / k;
        }
        while (cur <= 1000 && 2000 * dp[k] >= cur) {
            ans[cur++] = n;
        }
    }
    for (int i = 0; i < q; ++i) {
        int x;
        cin >> x;
        cout << ans[x] << " ";
    }

}


#include <bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(), (x).end()
#define int long long
const int N = 2000;
double dp[N];
int ans[N];
signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int k, q;
    cin >> k >> q;
    int cur = 1;
    dp[0] = 1;
    for (int n = 1; n <= 1000; ++n) {
        for (int x = k; x > 0; --x) {
            dp[x] = (x * dp[x] + (k - x + 1) * dp[x - 1]) / k;
        }
        while (cur <= 1000 && 2000 * dp[k] >= ((double)cur - 1e-7)) {
            ans[cur] = n;
            ++cur;
        }
        dp[0] = 0;
    }
    for (int i = 0; i < q; ++i) {
        int x;
        cin >> x;
        cout << ans[x] << " ";
    }

}


#include <bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(), (x).end()
#define int long long
const int N = 2000;
double dp[N];
int ans[N];
signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int k, q;
    cin >> k >> q;
    int cur = 1;
    dp[0] = 1;
    for (int n = 1; n <= 1000; ++n) {
        for (int x = k; x > 0; --x) {
            dp[x] = (x * dp[x] + (k - x + 1) * dp[x - 1]) / k;
        }
        while (cur <= 1000 && 2000 * dp[k] >= ((double)cur - (double)1e-7)) {
            ans[cur] = n;
            ++cur;
        }
        dp[0] = 0;
    }
    for (int i = 0; i < q; ++i) {
        int x;
        cin >> x;
        cout << ans[x] << " ";
    }

}


#include <bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(), (x).end()
#define int long long
const int N = 2000;
double dp[N];
int ans[N];
signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int k, q;
    cin >> k >> q;
    int cur = 1;
    dp[0] = 1;
    for (int n = 1; n <= 1000; ++n) {
        for (int x = k; x > 0; --x) {
            dp[x] = (x * dp[x] + (k - x + 1) * dp[x - 1]) / k;
        }
        while (cur <= 1000 && 2000 * dp[k] >= ((double)cur - 1e-7)) {
            ans[cur] = n;
            ++cur;
        }
    }
    for (int i = 0; i < q; ++i) {
        int x;
        cin >> x;
        cout << ans[x] << " ";
    }

}


#include <bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(), (x).end()
const int N = 2000;
double dp[N];
int ans[N];
signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int k, q;
    cin >> k >> q;
    int cur = 1;
    dp[0] = 1;
    for (int n = 1; n <= 1000; ++n) {
        for (int x = k; x > 0; --x) {
            dp[x] = (x * dp[x] + (k - x + 1) * dp[x - 1]) / k;
        }
        while (cur <= 1000 && 2000 * dp[k] >= cur) {
            ans[cur++] = n;
        }
    }
    for (int i = 0; i < q; ++i) {
        int x;
        cin >> x;
        cout << ans[x] << " ";
    }

}


#include <bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(), (x).end()
#define int long long
const int N = 2000;
double dp[N];
int ans[N];
signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int k, q;
    cin >> k >> q;
    int cur = 1;
    dp[0] = 1;
    for (int n = 1; n <= 1000; ++n) {
        for (int x = k; x > 0; --x) {
            dp[x] = (x * dp[x] + (k - x + 1) * dp[x - 1]) / k;
        }
        while (cur <= 1000 && 2000 * dp[k] >= cur - 1e7) {
            ans[cur] = n;
            ++cur;
        }
    }
    for (int i = 0; i < q; ++i) {
        int x;
        cin >> x;
        cout << ans[x] << " ";
    }

}


#include <bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(), (x).end()
#define int long long
const int N = 2000;
double dp[N];
int ans[N];
signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int k, q;
    cin >> k >> q;
    int cur = 1;
    dp[0] = 1;
    for (int n = 1; cur <= 1000; ++n) {
        for (int x = k; x > 0; --x) {
            dp[x] = (x * dp[x] + (k - x + 1) * dp[x - 1]) / k;
        }
        while (cur <= 1000 && 2000 * dp[k] >= ((double)cur - (double)1e-7)) {
            ans[cur] = n;
            ++cur;
        }
        dp[0] = 0;
    }
    for (int i = 0; i < q; ++i) {
        int x;
        cin >> x;
        cout << ans[x] << " ";
    }

}


#include <bits/stdc++.h>

using namespace std;

const long long int n = 20000;
long long int q, k;
double p, h, dp[n][1005], a[n], z, x;

int main() {
    cout << setprecision(14) << fixed;
    cin >> k >> q;
    for (int i = 0; i < n; i++){
        dp[i][0] = 1;
    }
    for (int i = 1; i < n; i++){
        for (int j = 1; j <= k; j++){
            dp[i][j] = dp[i - 1][j - 1] * (double)((k - j + 1) / k) + dp[i - 1][j] * (double)(j / k);
        }
    }
    cout << dp[1][1] << " " << dp[1][2] << " " << dp[2][1] << " " << dp[2][2];
    return 0;
    for (int i = 1; i < n; i++){
        a[i] += dp[i][k];
        cout << a[i] << " ";
    }
    while(q--){
        cin >> p;
        int l = 1, r = n;
        while (r - l > 1){
            int mid = (l + r) / 2;
            if (p / 2000 >= a[mid]){
                r = mid + 1;
            }else {
                l = mid + 1;
            }
        }
        cout << l << '\n';
    }
}


#include <bits/stdc++.h>

using namespace std;

const long long int n = 20000;
long long int k, q, p;
double h, dp[n][1005], a[n], z, x;

int main() {
    cout << setprecision(14) << fixed;
    cin >> k >> q;
    for (int i = 1; i < n; i++){
        dp[i][1] = 1;
    }
    for (int i = 2; i < n; i++){
        for (int j = 2; j <= k; j++){
            z = dp[i - 1][j];
            z *= j;
            z /= k;
            x = dp[i - 1][j - 1];
            x *= (k - j + 1);
            x /= k;
            dp[i][j] = z + x;
        }
    }
    for (int i = 1; i < n; i++){
        a[i] += dp[i][k];
        //cout << a[i] << " ";
    }
    while(q--){
        cin >> p;
        int l = 0, r = n - 1;
        while (r - l > 1){
            int mid = (l + r) / 2;
            if ( double(p - (2000 * a[mid])) <= 0.0000001){
                r = mid;
            }else {
                l = mid;
            }
        }
        cout << r << '\n';
    }
}


#include <bits/stdc++.h>

using namespace std;

const long long int n = 20000;
long long int q, k;
double p, h, dp[n][1005], a[n], z, x;

int main() {
    cout << setprecision(14) << fixed;
    cin >> k >> q;
    for (int i = 0; i < n; i++){
        dp[i][0] = 1;
    }
    for (int i = 1; i < n; i++){
        for (int j = 1; j <= k; j++){
            dp[i][j] = dp[i - 1][j - 1] * (double)(k - j + 1) / k + dp[i - 1][j] * (double)j / k;
        }
    }
    for (int i = 0; i < n; i++){
        a[i] = dp[i][k];
    }
    while(q--){
        cin >> p;
        for (int i = 0; i < n; i++){
            if (p <= a[i] * 2000.0){
                cout << i << '\n';
                break;
            }
        }
    }
}


#include <bits/stdc++.h>

using namespace std;

const long long int n = 20000;
long long int q, k;
double p, h, dp[n][1005], a[n], z, x;

int main() {
    cout << setprecision(14) << fixed;
    cin >> k >> q;
    /*for (int i = 1; i < n; i++){
        dp[i][1] = 1;
    }*/
    dp[0][0] = 0;
    for (int i = 1; i < n; i++){
        for (int j = 1; j <= k; j++){
            dp[i][j] = dp[i - 1][j - 1] * (double)((k - j + 1) / k) + dp[i - 1][j] * (double)(j / k);
        }
    }
    for (int i = 1; i < n; i++){
        a[i] += dp[i][k];
        //cout << a[i] << " ";
    }
    while(q--){
        cin >> p;
        int l = 1, r = n;
        while (r - l > 1){
            int mid = (l + r) / 2;
            if ( double(p - (2000 * a[mid])) < 0.0000001){
                r = mid;
            }else {
                l = mid;
            }
        }
        cout << r << '\n';
    }
}


#include <bits/stdc++.h>

using namespace std;

const long long int n = 20000;
long long int q;
double k, p, h, dp[n][1005], a[n], z, x;

int main() {
    cout << setprecision(14) << fixed;
    cin >> k >> q;
    */for (int i = 1; i < n; i++){
        dp[i][1] = 1;
    }*/
    dp[0][0] = 0;
    for (int i = 1; i < n; i++){
        for (int j = 1; j <= k; j++){
            z = dp[i - 1][j];
            z *= j;
            z /= k;
            x = dp[i - 1][j - 1];
            x *= (k - j + 1);
            x /= k;
            dp[i][j] = z + x;
        }
    }
    for (int i = 1; i < n; i++){
        int alo;
        alo = k;
        a[i] += dp[i][alo];
        cout << a[i] << " ";
    }
    while(q--){
        cin >> p;
        int l = 0, r = n - 1;
        while (r - l > 1){
            int mid = (l + r) / 2;
            if ( double(p - (2000 * a[mid])) < 0.0000001){
                r = mid;
            }else {
                l = mid;
            }
        }
        cout << r << '\n';
    }
}


#include <bits/stdc++.h>

using namespace std;

const long long int n = 20000;
long long int q, k;
double p, h, dp[n][1005], a[n], z, x;

int main() {
    cout << setprecision(14) << fixed;
    cin >> k >> q;
    dp[0][0] = 1;
    for (int i = 1; i < n; i++){
        for (int j = 1; j <= k; j++){
            dp[i][j] = dp[i - 1][j - 1] * (double)(k - j + 1) / k + dp[i - 1][j] * (double)j / k;
        }
    }
    for (int i = 0; i < n; i++){
        a[i] = dp[i][k];
    }
    while(q--){
        cin >> p;
        for (int i = 0; i < n; i++){
            if (p <= a[i] * 2000.0){
                cout << i << '\n';
                break;
            }
        }
    }
}


#include <bits/stdc++.h>

using namespace std;

const long long int n = 20000;
long long int q;
double k, p, h, dp[n][1005], a[n], z, x;

int main() {
    cout << setprecision(14) << fixed;
    cin >> k >> q;
    /*for (int i = 1; i < n; i++){
        dp[i][1] = 1;
    }*/
    dp[0][0] = 0;
    for (int i = 1; i < n; i++){
        for (int j = 1; j <= k; j++){
            z = dp[i - 1][j];
            z *= j;
            z /= k;
            x = dp[i - 1][j - 1];
            x *= (k - j + 1);
            x /= k;
            dp[i][j] = z + x;
        }
    }
    for (int i = 1; i < n; i++){
        int alo;
        alo = k;
        a[i] += dp[i][alo];
        //cout << a[i] << " ";
    }
    while(q--){
        cin >> p;
        int l = 0, r = n - 1;
        while (r - l > 1){
            int mid = (l + r) / 2;
            if ( double(p - (2000 * a[mid])) < 0.0000001){
                r = mid;
            }else {
                l = mid;
            }
        }
        cout << r << '\n';
    }
}


#include <bits/stdc++.h>

using namespace std;

const long long int n = 20000;
long long int q, k;
double p, h, dp[n][1005], a[n], z, x;

int main() {
    cout << setprecision(14) << fixed;
    cin >> k >> q;
    for (int i = 0; i < n; i++){
        dp[i][0] = 1;
    }
    for (int i = 1; i < n; i++){
        for (int j = 1; j <= k; j++){
            dp[i][j] = dp[i - 1][j - 1] * (double)(k - j + 1) / k + dp[i - 1][j] * (double)j / k;
        }
    }
    for (int i = 1; i < n; i++){
        a[i] += dp[i][k];
        //cout << a[i] << " ";
    }
    while(q--){
        cin >> p;
        int l = 1, r = n;
        while (r - l > 1){
            int mid = (l + r) / 2;
            if (p / 2000 <= a[mid]){
                r = mid + 1;
            }else {
                l = mid + 1;
            }
        }
        cout << l << '\n';
    }
}


#include <bits/stdc++.h>

using namespace std;

const long long int n = 20000;
long long int q;
double k, p, h, dp[n][1005], a[n], z, x;

int main() {
    cout << setprecision(14) << fixed;
    cin >> k >> q;
    /*for (int i = 1; i < n; i++){
        dp[i][1] = 1;
    }*/
    dp[0][0] = 0;
    for (int i = 1; i < n; i++){
        for (int j = 1; j <= k; j++){
            z = dp[i - 1][j];
            z *= j;
            z /= k;
            x = dp[i - 1][j - 1];
            x *= (k - j + 1);
            x /= k;
            dp[i][j] = z + x;
        }
    }
    for (int i = 1; i < n; i++){
        int alo;
        alo = k;
        a[i] += dp[i][alo];
        //cout << a[i] << " ";
    }
    while(q--){
        cin >> p;
        int l = 1, r = n - 1;
        while (r - l > 1){
            int mid = (l + r) / 2;
            if ( double(p - (2000 * a[mid])) < 0.0000001){
                r = mid;
            }else {
                l = mid;
            }
        }
        cout << r << '\n';
    }
}


#include <bits/stdc++.h>

using namespace std;

const long long int n = 20000;
long long int q;
double k, p, h, dp[n][1005], a[n], z, x;

int main() {
    cout << setprecision(14) << fixed;
    cin >> k >> q;
    /*for (int i = 1; i < n; i++){
        dp[i][1] = 1;
    }*/
    dp[0][0] = 0;
    for (int i = 1; i < n; i++){
        for (int j = 1; j <= k; j++){
            z = dp[i - 1][j];
            z *= j;
            z /= k;
            x = dp[i - 1][j - 1];
            x *= (k - j + 1);
            x /= k;
            dp[i][j] = z + x;
        }
    }
    for (int i = 1; i < n; i++){
        int alo;
        alo = k;
        a[i] += dp[i][alo];
        cout << a[i] << " ";
    }
    while(q--){
        cin >> p;
        int l = 0, r = n - 1;
        while (r - l > 1){
            int mid = (l + r) / 2;
            if ( double(p - (2000 * a[mid])) < 0.0000001){
                r = mid;
            }else {
                l = mid;
            }
        }
        cout << r << '\n';
    }
}


#include <bits/stdc++.h>

using namespace std;

const long long int n = 20000;
long long int q, k;
double p, h, dp[n][1005], a[n], z, x;

int main() {
    cout << setprecision(14) << fixed;
    cin >> k >> q;
    for (int i = 0; i < n; i++){
        dp[i][0] = 1;
    }
    for (int i = 1; i < n; i++){
        for (int j = 1; j <= k; j++){
            dp[i][j] = dp[i - 1][j - 1] * (double)(k - j + 1) / k + dp[i - 1][j] * (double)j / k;
        }
    }
    for (int i = 1; i < n; i++){
        a[i] = dp[i][k];
        //cout << a[i] << " ";
    }
    while(q--){
        cin >> p;
        int l = 1, r = n;
        while (r - l > 1){
            int mid = (l + r) / 2;
            if (p / 2000 <= a[mid]){
                r = mid + 1;
            }else {
                l = mid;
            }
        }
        cout << r << '\n';
    }
}


#include <bits/stdc++.h>

using namespace std;

const long long int n = 20000;
long long int k, q, p;
double h, dp[n][1005], a[n];

int main() {
    cout << setprecision(14) << fixed;
    cin >> k >> q;
    for (int i = 1; i < n; i++){
        dp[i][1] = 1;
    }
    for (int i = 2; i < n; i++){
        for (int j = 2; j <= k; j++){
            dp[i][j] = dp[i - 1][k] + double((dp[i - 1][k - 1] / k));
        }
    }
    for (int i = 1; i < n; i++){
        a[i] += dp[i][k];
        //cout << a[i] << " ";
    }
    while(q--){
        cin >> p;
        int l = 0, r = n - 1;
        while (r - l > 1){
            int mid = (l + r) / 2;
            if ( double(p - (2000 * a[mid])) <= 0.0000001){
                r = mid;
            }else {
                l = mid;
            }
        }
        cout << r << '\n';
    }
}


#include <bits/stdc++.h>

using namespace std;

const long long int n = 20000;
long long int q, k;
double p, h, dp[n][1005], a[n], z, x;

int main() {
    cout << setprecision(14) << fixed;
    cin >> k >> q;
    dp[0][0] = 1;
    for (int i = 1; i < n; i++){
        for (int j = 1; j <= k; j++){
            dp[i][j] = dp[i - 1][j - 1] * (double)((k - j + 1) / k) + dp[i - 1][j] * (double)(j / k);
        }
    }
    for (int i = 1; i < n; i++){
        a[i] += dp[i][k];
    }
    while(q--){
        cin >> p;
        int l = 1, r = n;
        while (r - l > 1){
            int mid = (l + r) / 2;
            if (p / 2000 >= a[mid]){
                r = mid + 1;
            }else {
                l = mid + 1;
            }
        }
        cout << l << '\n';
    }
}


#include <bits/stdc++.h>

using namespace std;

const long long int n = 20000;
long long int q, k;
double p, h, dp[n][1005], a[n], z, x;

int main() {
    cout << setprecision(14) << fixed;
    cin >> k >> q;
    for (int i = 0; i < n; i++){
        dp[i][0] = 1;
    }
    for (int i = 1; i < n; i++){
        for (int j = 1; j <= k; j++){
            dp[i][j] = dp[i - 1][j - 1] * (double)(k - j + 1) / k + dp[i - 1][j] * (double)j / k;
        }
    }
    for (int i = 1; i < n; i++){
        a[i] += dp[i][k];
        //cout << a[i] << " ";
    }
    while(q--){
        cin >> p;
        int l = 1, r = n;
        while (r - l > 1){
            int mid = (l + r) / 2;
            if (p / 2000 <= a[mid]){
                r = mid;
            }else {
                l = mid;
            }
        }
        cout << l << '\n';
    }
}


#include <bits/stdc++.h>

using namespace std;

const long long int n = 20000;
long long int q, k;
double p, h, dp[n][1005], a[n], z, x;

int main() {
    cout << setprecision(14) << fixed;
    cin >> k >> q;
    dp[0][0] = 1;
    for (int i = 1; i < n; i++){
        for (int j = 1; j <= k; j++){
            dp[i][j] = dp[i - 1][j - 1] * (double)((k - j + 1) / k) + dp[i - 1][j] * (double)(j / k);
        }
    }
    for (int i = 1; i < n; i++){
        a[i] += dp[i][k];
    }
    while(q--){
        cin >> p;
        int l = 1, r = n;
        while (r - l > 1){
            int mid = (l + r) / 2;
            if ( double(p - (2000 * a[mid])) < 0.0000001){
                r = mid;
            }else {
                l = mid;
            }
        }
        cout << l << '\n';
    }
}


#include <bits/stdc++.h>

using namespace std;

const long long int n = 20000;
long long int q;
double k, p, h, dp[n][1005], a[n], z, x;

int main() {
    cout << setprecision(14) << fixed;
    cin >> k >> q;
    /*for (int i = 1; i < n; i++){
        dp[i][1] = 1;
    }*/
    dp[0][0] = 0;
    for (int i = 1; i < n; i++){
        for (int j = 1; j <= k; j++){
            z = dp[i - 1][j];
            z *= j;
            z /= k;
            x = dp[i - 1][j - 1];
            x *= (k - j + 1);
            x /= k;
            dp[i][j] = z + x;
        }
    }
    for (int i = 1; i < n; i++){
        int alo;
        alo = k;
        a[i] += dp[i][alo];
        //cout << a[i] << " ";
    }
    while(q--){
        cin >> p;
        int l = 1, r = n;
        while (r - l > 1){
            int mid = (l + r) / 2;
            if ( double(p - (2000 * a[mid])) < 0.0000001){
                r = mid;
            }else {
                l = mid;
            }
        }
        cout << r << '\n';
    }
}


#include <bits/stdc++.h>

using namespace std;

const long long int n = 20000;
long long int q, k;
double p, h, dp[n][1005], a[n], z, x;

int main() {
    cout << setprecision(14) << fixed;
    cin >> k >> q;
    for (int i = 0; i < n; i++){
        dp[i][0] = 1;
    }
    for (int i = 1; i < n; i++){
        for (int j = 1; j <= k; j++){
            dp[i][j] = dp[i - 1][j - 1] * (double)(k - j + 1) / k + dp[i - 1][j] * (double)j / k;
        }
    }
    for (int i = 0; i < n; i++){
        a[i] = dp[i][k];
    }
    while(q--){
        cin >> p;
        for (int i = 0; i < n; i++){
            if (p - a[i] * 2000.0 < 0.0000001){
                cout << i << '\n';
                break;
            }
        }
    }
}


#include <bits/stdc++.h>

using namespace std;

const long long int n = 20000;
long long int q, k;
double p, h, dp[n][1005], a[n], z, x;

int main() {
    cout << setprecision(14) << fixed;
    cin >> k >> q;
    dp[0][0] = 1;
    for (int i = 1; i < n; i++){
        for (int j = 1; j <= k; j++){
            dp[i][j] = dp[i - 1][j - 1] * (double)((k - j + 1) / k) + dp[i - 1][j] * (double)(j / k);
        }
    }
    for (int i = 1; i < n; i++){
        a[i] += dp[i][k];
    }
    while(q--){
        cin >> p;
        int l = 1, r = n;
        while (r - l > 1){
            int mid = (l + r) / 2;
            if ( double(p - (2000 * a[mid])) < 0.0000001){
                r = mid;
            }else {
                l = mid;
            }
        }
        cout << r << '\n';
    }
}


#include <bits/stdc++.h>

using namespace std;

const long long int n = 20000;
long long int q, k;
double p, h, dp[n][1005], a[n], z, x;

int main() {
    cout << setprecision(14) << fixed;
    cin >> k >> q;
    for (int i = 0; i < n; i++){
        dp[i][0] = 1;
    }
    for (int i = 1; i < n; i++){
        for (int j = 1; j <= k; j++){
            dp[i][j] = dp[i - 1][j - 1] * (double)(k - j + 1) / k + dp[i - 1][j] * (double)j / k;
        }
    }
    for (int i = 1; i < n; i++){
        a[i] += dp[i][k];
        //cout << a[i] << " ";
    }
    while(q--){
        cin >> p;
        int l = 1, r = n;
        while (r - l > 1){
            int mid = (l + r) / 2;
            if (p / 2000 <= a[mid]){
                r = mid;
            }else {
                l = mid;
            }
        }
        cout << r << '\n';
    }
}


#include <bits/stdc++.h>

using namespace std;

const long long int n = 20000;
long long int q, k;
double p, h, dp[n][1005], a[n], z, x;

int main() {
    cout << setprecision(14) << fixed;
    cin >> k >> q;
    for (int i = 0; i < n; i++){
        dp[i][0] = 1;
    }
    for (int i = 1; i < n; i++){
        for (int j = 1; j <= k; j++){
            dp[i][j] = dp[i - 1][j - 1] * (double)(k - j + 1) / k + dp[i - 1][j] * (double)j / k;
        }
    }
    for (int i = 1; i < n; i++){
        a[i] += dp[i][k];
        //cout << a[i] << " ";
    }
    while(q--){
        cin >> p;
        int l = 1, r = n;
        while (r - l > 1){
            int mid = (l + r) / 2;
            if (p / 2000 >= a[mid]){
                r = mid + 1;
            }else {
                l = mid + 1;
            }
        }
        cout << l << '\n';
    }
}


#include <bits/stdc++.h>

using namespace std;

const long long int n = 20000;
long long int q, k;
double p, h, dp[n][1005], a[n], z, x;

int main() {
    cout << setprecision(14) << fixed;
    cin >> k >> q;
    for (int i = 0; i < n; i++){
        dp[i][0] = 1;
    }
    for (int i = 1; i < n; i++){
        for (int j = 1; j <= k; j++){
            dp[i][j] = dp[i - 1][j - 1] * (double)(k - j + 1) / k + dp[i - 1][j] * (double)j / k;
        }
    }
    for (int i = 1; i < n; i++){
        a[i] = dp[i][k];
        //cout << a[i] << " ";
    }
    while(q--){
        cin >> p;
        int l = 0, r = n - 1;
        while (r - l > 1){
            int mid = (l + r) / 2;
            if (p / 2000 <= a[mid]){
                r = mid;
            }else {
                l = mid;
            }
        }
        cout << r << '\n';
    }
}


#include <bits/stdc++.h>

using namespace std;

const long long int n = 20000;
long long int q, k;
double p, h, dp[n][1005], a[n], z, x;

int main() {
    cout << setprecision(14) << fixed;
    cin >> k >> q;
    for (int i = 0; i < n; i++){
        dp[i][0] = 1;
    }
    for (int i = 1; i < n; i++){
        for (int j = 1; j <= k; j++){
            dp[i][j] = dp[i - 1][j - 1] * (double)(k - j + 1) / k + dp[i - 1][j] * (double)j / k;
        }
    }
    for (int i = 1; i < n; i++){
        a[i] += dp[i][k];
        //cout << a[i] << " ";
    }
    while(q--){
        cin >> p;
        int l = 1, r = n;
        while (r - l > 1){
            int mid = (l + r) / 2;
            if (p / 2000 <= a[mid]){
                r = mid;
            }else {
                l = mid + 1;
            }
        }
        cout << l << '\n';
    }
}


#include <bits/stdc++.h>

using namespace std;

const long long int n = 20000;
long long int q, k;
double p, h, dp[n][1005], a[n], z, x;

int main() {
    cout << setprecision(14) << fixed;
    cin >> k >> q;
    for (int i = 0; i < n; i++){
        dp[i][0] = 1;
    }
    for (int i = 1; i < n; i++){
        for (int j = 1; j <= k; j++){
            dp[i][j] = dp[i - 1][j - 1] * (double)(k - j + 1) / k + dp[i - 1][j] * (double)j / k;
        }
    }
    for (int i = 1; i < n; i++){
        a[i] = dp[i][k];
        //cout << a[i] << " ";
    }
    while(q--){
        cin >> p;
        for (int i = 0; i < n; i++){
            if (p - a[i] * 2000 < 0.0000001){
                cout << i << '\n';
                break;
            }
        }
    }
}


#include <bits/stdc++.h>

using namespace std;

const long long int n = 20000;
long long int q, k;
double p, h, dp[n][1005], a[n], z, x;

int main() {
    cout << setprecision(14) << fixed;
    cin >> k >> q;
    for (int i = 0; i < n; i++){
        dp[i][0] = 1;
    }
    for (int i = 1; i < n; i++){
        for (int j = 1; j <= k; j++){
            dp[i][j] = dp[i - 1][j - 1] * (double)(k - j + 1) / k + dp[i - 1][j] * (double)j / k;
        }
    }
    for (int i = 1; i < n; i++){
        a[i] += dp[i][k];
        //cout << a[i] << " ";
    }
    while(q--){
        cin >> p;
        int l = 1, r = n;
        while (r - l > 1){
            int mid = (l + r) / 2;
            if (p / 2000 <= a[mid]){
                r = mid;
            }else {
                l = mid + 1;
            }
        }
        cout << r << '\n';
    }
}


#include <bits/stdc++.h>

using namespace std;

const long long int n = 20000;
long long int q, k;
double p, h, dp[n][1005], a[n], z, x;

int main() {
    cout << setprecision(14) << fixed;
    cin >> k >> q;
    for (int i = 0; i < n; i++){
        dp[i][0] = 1;
    }
    for (int i = 1; i < n; i++){
        for (int j = 1; j <= k; j++){
            dp[i][j] = dp[i - 1][j - 1] * (double)(k - j + 1) / k + dp[i - 1][j] * (double)j / k;
        }
    }
    for (int i = 1; i < n; i++){
        a[i] += dp[i][k];
        //cout << a[i] << " ";
    }
    while(q--){
        cin >> p;
        int l = 0, r = n - 1;
        while (r - l > 1){
            int mid = (l + r) / 2;
            if (p / 2000 <= a[mid]){
                r = mid;
            }else {
                l = mid;
            }
        }
        cout << r << '\n';
    }
}


//~ while (clock()<=69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")
//~ #pragma GCC optimize("O3")
//~ #pragma GCC optimize("Ofast")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//~ #pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define pb push_back
#define SZ(x) ((int)(x).size())
#define ALL(x) x.begin(),x.end()
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define _upgrade ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define erase_duplicates(x) sort(all(x)); (x).resize(distance((x).begin(), unique(all(x))));

using namespace std;
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<
T,
null_type,
less<T>,
rb_tree_tag,
tree_order_statistics_node_update>;

//X.find_by_order(k); - zwraca iterator na k-ty element (numeracja od zerowego)
//X.order_of_key(k); - zwraca liczbę elementów ostro mniejszych niż k

typedef long long LL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
typedef vector<PII> VPII;
typedef vector<PLL> VPLL;
typedef vector<LL> VLL;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long double LD;
typedef pair<LD,LD> PLD;
typedef vector<LD> VLD;
typedef vector<PLD> VPLD;

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<" = "<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;
  cerr<<" = "<<h<<", "; _dbg(sdbg+1, a...);
}

#ifdef LOCAL
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(...)
#define cerr if(0)cout
#endif

const int maxn = (2e3)+7;
const int maxk = 20;
const int inf = (1e9)+7;
const LL LLinf = ((LL)1e18)+7LL;
const LD eps = 1e-9;
const LL mod = 1e9+7;

// ***************************** CODE ***************************** //

LD dp[3][1005];
int odp[maxn];

int main()
{
	_upgrade
  int k, q;
  cin>>k>>q;
  dp[0][0] = 1.0;
  int wsk = 1;
  int cur = 0;
  for(int i = 0;wsk <= 1000;i++)
  {
    // dbg(i);
    for(int j = 0 ;j <= k;j++)
      dp[cur ^ 1][j] = 0.0;
    for(int j = 0;j <= k;j++)
    {
      dp[cur ^ 1][j + 1] += dp[cur][j] * ((k - j) / (LD) k);
      dp[cur ^ 1][j] += dp[cur][j] * (j / (LD)k);
    }
    while(i > 0 && wsk <= 1000 && 2000.0 * dp[cur][k] >= wsk - 1e-7)
      odp[wsk++] = i;
    cur ^= 1;
  }
  while(q--)
  {
    int a;
    cin>>a;
    cout<<odp[a]<<"\n";
  }
	return 0;
}


//~ while (clock()<=69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")
//~ #pragma GCC optimize("O3")
//~ #pragma GCC optimize("Ofast")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//~ #pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define pb push_back
#define SZ(x) ((int)(x).size())
#define ALL(x) x.begin(),x.end()
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define _upgrade ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define erase_duplicates(x) sort(all(x)); (x).resize(distance((x).begin(), unique(all(x))));

using namespace std;
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<
T,
null_type,
less<T>,
rb_tree_tag,
tree_order_statistics_node_update>;

//X.find_by_order(k); - zwraca iterator na k-ty element (numeracja od zerowego)
//X.order_of_key(k); - zwraca liczbę elementów ostro mniejszych niż k

typedef long long LL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
typedef vector<PII> VPII;
typedef vector<PLL> VPLL;
typedef vector<LL> VLL;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef double LD;
typedef pair<LD,LD> PLD;
typedef vector<LD> VLD;
typedef vector<PLD> VPLD;

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<" = "<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;
  cerr<<" = "<<h<<", "; _dbg(sdbg+1, a...);
}

#ifdef LOCAL
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(...)
#define cerr if(0)cout
#endif

const int maxn = (2e3)+7;
const int maxk = 20;
const int inf = (1e9)+7;
const LL LLinf = ((LL)1e18)+7LL;
const LD eps = 1e-9;
const LL mod = 1e9+7;

// ***************************** CODE ***************************** //

LD dp[3][1005];
int odp[maxn];

int main()
{
	_upgrade
  int k, q;
  cin>>k>>q;
  dp[0][0] = 1.0;
  int wsk = 1;
  int cur = 0;
  for(int i = 0;wsk <= 1001;i++)
  {
    // dbg(i);
    for(int j = 0 ;j <= k;j++)
      dp[cur ^ 1][j] = 0.0;
    for(int j = 0;j <= k;j++)
    {
      dp[cur ^ 1][j + 1] += dp[cur][j] * ((k - j + 1.0) / (LD) k);
      dp[cur ^ 1][j] += dp[cur][j] * (j / (LD)k);
    }
    while(wsk <= 1001 && dp[cur][k] >= wsk / (LD)2000.0)
      odp[wsk++] = i;
    cur ^= 1;
  }
  while(q--)
  {
    int a;
    cin>>a;
    cout<<odp[a]<<"\n";
  }
	return 0;
}


//~ while (clock()<=69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")
//~ #pragma GCC optimize("O3")
//~ #pragma GCC optimize("Ofast")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//~ #pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define pb push_back
#define SZ(x) ((int)(x).size())
#define ALL(x) x.begin(),x.end()
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define _upgrade ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define erase_duplicates(x) sort(all(x)); (x).resize(distance((x).begin(), unique(all(x))));

using namespace std;
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<
T,
null_type,
less<T>,
rb_tree_tag,
tree_order_statistics_node_update>;

//X.find_by_order(k); - zwraca iterator na k-ty element (numeracja od zerowego)
//X.order_of_key(k); - zwraca liczbę elementów ostro mniejszych niż k

typedef long long LL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
typedef vector<PII> VPII;
typedef vector<PLL> VPLL;
typedef vector<LL> VLL;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef double LD;
typedef pair<LD,LD> PLD;
typedef vector<LD> VLD;
typedef vector<PLD> VPLD;

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<" = "<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;
  cerr<<" = "<<h<<", "; _dbg(sdbg+1, a...);
}

#ifdef LOCAL
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(...)
#define cerr if(0)cout
#endif

const int maxn = (2e3)+7;
const int maxk = 20;
const int inf = (1e9)+7;
const LL LLinf = ((LL)1e18)+7LL;
const LD eps = 1e-9;
const LL mod = 1e9+7;

// ***************************** CODE ***************************** //

LD dp[3][1005];
int odp[maxn];

int main()
{
	_upgrade
  int k, q;
  cin>>k>>q;
  dp[0][0] = 1.0;
  int wsk = 1;
  int cur = 0;
  for(int i = 0;wsk <= 1000;i++)
  {
    // dbg(i);
    for(int j = 0 ;j<= k;j++)
      dp[cur ^ 1][j] = 0.0;
    for(int j = 0;j <= k;j++)
      if(dp[cur][j] > eps)
      {
        dp[cur ^ 1][j + 1] += dp[cur][j] * ((k - j) / (LD) k);
        dp[cur ^ 1][j] += dp[cur][j] * (j / (LD)k);
      }
    while(wsk <= 1000 && dp[cur][k] >= wsk / (LD)2000.0)
      odp[wsk++] = i;
    cur ^= 1;
  }
  while(q--)
  {
    int a;
    cin>>a;
    cout<<odp[a]<<"\n";
  }
	return 0;
}


//~ while (clock()<=69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")
//~ #pragma GCC optimize("O3")
//~ #pragma GCC optimize("Ofast")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//~ #pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define pb push_back
#define SZ(x) ((int)(x).size())
#define ALL(x) x.begin(),x.end()
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define _upgrade ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define erase_duplicates(x) sort(all(x)); (x).resize(distance((x).begin(), unique(all(x))));

using namespace std;
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<
T,
null_type,
less<T>,
rb_tree_tag,
tree_order_statistics_node_update>;

//X.find_by_order(k); - zwraca iterator na k-ty element (numeracja od zerowego)
//X.order_of_key(k); - zwraca liczbę elementów ostro mniejszych niż k

typedef long long LL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
typedef vector<PII> VPII;
typedef vector<PLL> VPLL;
typedef vector<LL> VLL;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long double LD;
typedef pair<LD,LD> PLD;
typedef vector<LD> VLD;
typedef vector<PLD> VPLD;

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<" = "<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;
  cerr<<" = "<<h<<", "; _dbg(sdbg+1, a...);
}

#ifdef LOCAL
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(...)
#define cerr if(0)cout
#endif

const int maxn = (2e3)+7;
const int maxk = 20;
const int inf = (1e9)+7;
const LL LLinf = ((LL)1e18)+7LL;
const LD eps = 1e-9;
const LL mod = 1e9+7;

// ***************************** CODE ***************************** //

LD dp[maxn][maxn];
int odp[maxn];

int main()
{
	_upgrade
  int k, q;
  cin>>k>>q;
  dp[0][0] = 1.0;
  for(int i = 0;i + 1 < maxn;i++)
    for(int j = 0;j <= k;j++)
      if(dp[i][j] > eps)
      {
        dp[i + 1][j + 1] += dp[i][j] * ((k - j) / (LD) k);
        dp[i + 1][j] += dp[i][j] * (j / (LD)k);
      }
  int wsk = 1;
  for(int i = 1;wsk <= 1000;i++)
    while(wsk <= 1000 && dp[i][k] >= wsk / (LD)2000.0)
      odp[wsk++] = i;
  while(q--)
  {
    int a;
    cin>>a;
    cout<<odp[a]<<"\n";
  }
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <bitset>

using namespace std;
const int N=10000;
double dp[N+1][1005];

int main()
{
    int n;
    cin >> n;
    dp[0][0]=1;
    for (int i=0;i<N;i++){

        dp[i+1][1]+=dp[i][0];

        for (int j=1;j<n;j++){
            dp[i+1][j+1]+=(double)j/n*dp[i][j];
            dp[i+1][j]+=(double)(n-j)/n*dp[i][j];
        }

        dp[i+1][n]+=dp[i][n];
    }

    int q;
    cin >> q;
    while(q--){
        int P;
        cin >> P;
        double p=P/2000.0;
        for (int i=0;i<=N;i++){
            if (dp[i][n]>=p){
                cout << i << endl;
                break;
            }
        }
    }

    return 0;
}


/*
    Soheil Mohammadkhani
    Sos Goge Tabarok :)
*/
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;

#define all(x)                      (x).begin(),(x).end()
#define X                           first
#define Y                           second
#define sep                         ' '
#define endl                        '\n'
#define debug(x)                    cerr << #x << ": " <<  x << endl;
#define alog(a, n)                  for (int i = 0; i < n; i++) cout << a[i] << " "; cout << endl;
#define fast_io                     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

const ll MAXN = 1e4 + 10;
const ll MAXK = 1e3 + 10;
const ll INF = 8e18;
const ll MOD = 1e9 + 7; // 998244353; // 1e9 + 9;
const ld EPS = 1e-7;

ld dp[MAXN][MAXK] = {0};

int main() {
	fast_io;
	ll k, q;
	cin >> k >> q;
	dp[0][0] = 1;
	for (int i = 0; i < MAXN - 1; i++) {
		for (int j = 0; j <= k; j++) {
			ld p1 = dp[i][j] * ld(j) / ld(k);
			ld p2 = dp[i][j] - p1;

			dp[i + 1][j] += p1;
		      	dp[i + 1][j + 1] += p2;
		}
	}

	while (q--) {
		ld p;
		cin >> p;
		for (int i = 0; i < MAXN; i++) if (dp[i][k] + EPS > ld(p / 2000)) {
			cout << i << endl;
			break;
		}
	}
}


/*
    Soheil Mohammadkhani
    Sos Goge Tabarok :)
*/
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;

#define all(x)                      (x).begin(),(x).end()
#define X                           first
#define Y                           second
#define sep                         ' '
#define endl                        '\n'
#define debug(x)                    cerr << #x << ": " <<  x << endl;
#define alog(a, n)                  for (int i = 0; i < n; i++) cout << a[i] << " "; cout << endl;
#define fast_io                     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

const ll MAXN = 3e4 + 10;
const ll MAXK = 1e3 + 10;
const ll INF = 8e18;
const ll MOD = 1e9 + 7; // 998244353; // 1e9 + 9;
const ld EPS = 1e-7;

ld dp[MAXN][MAXK] = {0};

int main() {
	fast_io;
	ll k, q;
	cin >> k >> q;
	dp[0][0] = 1;
	for (int i = 0; i < MAXN - 1; i++) {
		for (int j = 0; j <= k; j++) {
			ld p1 = dp[i][j] * ld(j) / ld(k);
			ld p2 = dp[i][j] - p1;

			dp[i + 1][j] += p1;
		      	dp[i + 1][j + 1] += p2;
		}
	}

	while (q--) {
		ld p;
		cin >> p;
		for (int i = 0; i < MAXN; i++) if (dp[i][k] + EPS > ld(p / 2000)) {
			cout << i << endl;
			break;
		}
	}
}


/*
    Soheil Mohammadkhani
    Sos Goge Tabarok :)
*/
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;

#define all(x)                      (x).begin(),(x).end()
#define X                           first
#define Y                           second
#define sep                         ' '
#define endl                        '\n'
#define debug(x)                    cerr << #x << ": " <<  x << endl;
#define alog(a, n)                  for (int i = 0; i < n; i++) cout << a[i] << " "; cout << endl;
#define fast_io                     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

const ll MAXN = 1e4 + 10;
const ll MAXK = 1e3 + 10;
const ll INF = 8e18;
const ll MOD = 1e9 + 7; // 998244353; // 1e9 + 9;
const ld EPS = 1e-7;

ld dp[MAXN][MAXK] = {0};

int main() {
	fast_io;
	ll k, q;
	cin >> k >> q;
	dp[0][0] = 1;
	for (int i = 0; i < MAXN - 1; i++) {
		for (int j = 0; j <= k; j++) {
			ld p1 = dp[i][j] * ld(j) / ld(k);
			ld p2 = dp[i][j] - p1;

			dp[i + 1][j] += p1;
		      	dp[i + 1][j + 1] += p2;
		}
	}

	while (q--) {
		ld p;
		cin >> p;
		for (int i = 0; i < MAXN; i++) if (dp[i][k] > ld(p - EPS) / ld(2000)) {
			cout << i << endl;
			break;
		}
	}
}


//xtwakioi! xtwddYnoi(双重含义)!
#include <bits/stdc++.h>
#define ri register
#define int long long
#define E (n+1)
#define mk make_pair
using namespace std; const int N=2010;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar();
    return s*w;
}
int K,Q;
int p[N];
double dp[N*5][N];
signed main()
{
	K=read(), Q=read();
    for(ri int i=1;i<=Q;i++) p[i]=read();
    dp[0][0]=1;
    for(ri int i=1;i<=10000;i++)
    for(ri int j=1;j<=K;j++)
    dp[i][j]=1.0*dp[i-1][j]*j/K+1.0*dp[i-1][j-1]*(K-j+1)/K;

    /*for(ri int i=1;i<=5;i++,puts(""))
    for(ri int j=1;j<=K;j++)
    printf("%.5lf ",dp[i][j]);*/
    for(ri int i=1;i<=Q;i++)
    {
        for(ri int j=K;j<=10000;j++) if(dp[j][K]>=1.0*p[i]/2000) { printf("%lld\n",j); break; }
    }
    return 0;
}


//xtwakioi! xtwddYnoi(双重含义)!
#include <bits/stdc++.h>
#define ri register
#define int long long
#define E (n+1)
#define mk make_pair
using namespace std; const int N=2010;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar();
    return s*w;
}
int K,Q;
int p[N];
double dp[N][N];
signed main()
{
	K=read(), Q=read();
    for(ri int i=1;i<=Q;i++) p[i]=read();
    dp[0][0]=1;
    for(ri int i=1;i<=2000;i++)
    for(ri int j=1;j<=K;j++)
    dp[i][j]=1.0*dp[i-1][j]*j/K+1.0*dp[i-1][j-1]*(K-j+1)/K;

    /*for(ri int i=1;i<=5;i++,puts(""))
    for(ri int j=1;j<=K;j++)
    printf("%.5lf ",dp[i][j]);*/
    for(ri int i=1;i<=Q;i++)
    {
        for(ri int j=K;j<=2000;j++) if(dp[j][K]>=1.0*p[i]/2000) { printf("%lld\n",j); break; }
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef string str;

#define all(x)                      (x).begin(),(x).end()
#define Sort(x)                     sort(all((x)))
#define X                           first
#define Y                           second
#define Mp                          make_pair
#define sep                         ' '
#define endl                        '\n'
#define debug(x)                    cerr << #x << " = " << x << endl
#define SZ(x)                       ll(x.size())
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const ll MAXN = 2e3 + 10;
const ll MAXM = 1e3 + 10;
const ll INF = 8e18;
const ll MOD = 1e9 + 9; // 998244353; // 1e9 + 9;

ld dp[MAXN][MAXM];

int main(){

    fast_io;
    ll s , k = 1 , w;
    cin >> s >> w;
    memset(dp[1] , 0 , sizeof dp[0]);
    dp[1][1] = 1;
    while(dp[k][s] < 0.5){
        k ++;
        dp[k][1] = 1;
        ld q , r;
        for(int j = 2; j <= s; j++){
            q = 1.0 * j / k;
            r = 1.0 * (k - j + 1) / k;
            q = 1.0 * dp[k - 1][j] * q;
            r = 1.0 * dp[k - 1][j - 1] * r;
            dp[k][j] = q + r;
            //cout << k << sep << j << sep << r << sep << q << sep << dp[k][j] << endl;
        }
        //cout << dp[k][s] << endl;
    }
    for(int i = 0; i < w; i++){
        ld p;
        cin >> p;
        p = 1.0 * p / 2000;
        k = 1;
        while(dp[k][s] < p){
            k ++;
        }
        cout << k << endl;
    }

}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef string str;

#define all(x)                      (x).begin(),(x).end()
#define Sort(x)                     sort(all((x)))
#define X                           first
#define Y                           second
#define Mp                          make_pair
#define sep                         ' '
#define endl                        '\n'
#define debug(x)                    cerr << #x << " = " << x << endl
#define SZ(x)                       ll(x.size())
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const ll MAXN = 1e4 + 10;
const ll MAXM = 1e3 + 10;
const ll INF = 8e18;
const ll MOD = 1e9 + 9; // 998244353; // 1e9 + 9;

ld dp[MAXN][MAXM];

int main(){

    fast_io;
    ll s , k = 1 , w;
    cin >> s >> w;
    memset(dp[1] , 0 , sizeof dp[0]);
    dp[1][1] = 1;
    while(dp[k][s] < 0.5){
        k ++;
        ld q , r;
        q = 1.0 * dp[k - 1][1] / s;
        dp[k][1] = q;
        for(int j = 2; j <= s; j++){
            q = 1.0 * j / s;
            r = 1.0 * (s - j + 1) / s;
            q = 1.0 * dp[k - 1][j] * q;
            r = 1.0 * dp[k - 1][j - 1] * r;
            dp[k][j] = q + r;
            //cout << k << sep << j << sep << r << sep << q << sep << dp[k][j] << endl;
        }
        //cout << dp[k][s] << endl;
    }
    for(int i = 0; i < w; i++){
        ld p;
        cin >> p;
        p = 1.0 * p / 2000;
        k = 1;
        while(dp[k][s] < p){
            k ++;
        }
        cout << k << endl;
    }

}


#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll ;
typedef long double ld ;
typedef pair<ll , ll> pll ;

const ll N = 1e3 + 30 , Mod = 1e9 + 7 ;
const ll SQ = 330 ;
const ld Eps = 1e-7 ;

ld dp[N * 10][N] ;
int main () {
    ios::sync_with_stdio(0), cin.tie(0) ;
    ll k , q ;
    cin >> k >> q ;
    dp[0][0] = 1.0 ;
    for (int i = 1;  i < N * 10 ; i ++)
    	for (int j = 1 ; j <= k ; j ++)
    		dp[i][j] = (dp[i - 1][j] * j + dp[i - 1][j - 1] * (k - (j - 1.0))) / k ;
    while (q --) {
    	ll x ;
    	cin >> x ;
    	for (int i = 1 ; i <= 10000 ; i ++) {
    		if (x - Eps <= dp[i][k] * 2000) {
    			cout << i << '\n' ;
    			break ;
			}
		}
	}

    return (0) ;
}


By pouya_navid, contest: Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined), problem: (D) Jon and Orbs, Accepted, #
 #include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll ;
typedef long double ld ;
typedef pair<ll , ll> pll ;

const ll N = 1e3 + 30 , Mod = 1e9 + 7 ;
const ll SQ = 330 ;
const ld Eps = 1e-7 ;

ld dp[N * 10][N] ;
int main () {
    ios::sync_with_stdio(0), cin.tie(0) ;
    ll k , q ;
    cin >> k >> q ;
    dp[0][0] = 1.0 ;
    for (int i = 1;  i < N * 10 ; i ++)
    	for (int j = 1 ; j <= k ; j ++)
    		dp[i][j] = (dp[i - 1][j] * j + dp[i - 1][j - 1] * (k - (j - 1.0))) / k ;
    while (q --) {
    	ll x ;
    	cin >> x ;
    	for (int i = 1 ; i <= 10000 ; i ++) {
    		if (x - Eps <= dp[i][k] * 2000) {
    			cout << i << '\n' ;
    			break ;
			}
		}
	}

    return (0) ;
}


#include <bits/stdc++.h>
using namespace std;
long double pr[2][1002];
vector<long double> prr;
long double eps=1e-15;
int main()
{
    int k,q,i,j;
    scanf("%d%d",&k,&q);
    pr[0][0]=1;
    for(i=1;1;i++){
        memset(pr[i&1],0,sizeof(pr[i&1]));
        for(j=0;j<=k;j++){
            pr[i&1][j]+=pr[i&1^1][j]*j/k;
            pr[i&1][j+1]+=pr[i&1^1][j]*(k-j)/k;
        }
        prr.push_back(pr[i&1][k]);
        if(pr[i&1][k]>0.5001)break;
    }
    while(q--){
        int p;
        scanf("%d",&p);
        int cur=0;
        for(i=1<<30;i;i>>=1){
            if(cur+i>=prr.size())continue;
            if(prr[cur+i]*2000+eps<p)cur+=i;
        }
        printf("%d\n",cur+1);
    }
}


#include <bits/stdc++.h>
using namespace std;
long double pr[2][1002];
vector<long double> prr;
long double eps=1e-15;
int main()
{
    int k,q,i,j;
    scanf("%d%d",&k,&q);
    pr[0][0]=1;
    prr.push_back(0);
    for(i=1;1;i++){
        memset(pr[i&1],0,sizeof(pr[i&1]));
        for(j=0;j<=k;j++){
            pr[i&1][j]+=pr[i&1^1][j]*j/k;
            pr[i&1][j+1]+=pr[i&1^1][j]*(k-j)/k;
        }
        prr.push_back(pr[i&1][k]);
        if(pr[i&1][k]>0.5001)break;
    }
    while(q--){
        int p;
        scanf("%d",&p);
        int cur=0;
        for(i=1<<30;i;i>>=1){
            if(cur+i>=prr.size())continue;
            if(prr[cur+i]*2000+eps<p)cur+=i;
        }
        printf("%d\n",cur+1);
    }
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define PB push_back
#define F first
#define S second
#define MP make_pair
#define endl '\n'

const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 1000000007

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

//
//debug
template<typename F,typename S>ostream&operator<<(ostream&os,const pair<F,S>&p){return os<<"("<<p.first<<", "<<p.second<<")";}
template<typename T>ostream&operator<<(ostream&os,const vector<T>&v){os<<"{";for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin())os<<", ";os<<*it;}return os<<"}";}
template<typename T>ostream&operator<<(ostream&os,const set<T>&v){os<<"[";for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin())os<<",";os<<*it;}return os<<"]";}
template<typename T>ostream&operator<<(ostream&os,const multiset<T>&v) {os<<"[";for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin())os<<", ";os<<*it;}return os<<"]";}
template<typename F,typename S>ostream&operator<<(ostream&os,const map<F,S>&v){os<<"[";for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin())os<<", ";os<<it->first<<" = "<<it->second;}return os<<"]";}
#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)
void faltu(){cerr << endl;}
template<typename T>void faltu(T a[],int n){for(int i=0;i<n;++i)cerr<<a[i]<<' ';cerr<<endl;}
template<typename T,typename...hello>void faltu(T arg,const hello&...rest){cerr<<arg<<' ';faltu(rest...);}
//#else
//#define dbg(args...)

const double eps = 1e-7;

int k, q;
double dp[10005][1005];
int ans[1005];

int main()
{
	optimize();
	cin >> k >> q;
	dp[0][0] = 1;
	for( int day = 1; day < 10005; ++day ) {
		for( int x = 1; x <= k; ++x ) {
			dp[day][x] += ((double)x/(double)k)*dp[day-1][x] + ((double)(k-x+1)/(double)k)*dp[day-1][x-1];
		}
	}
	int cur = 0;
	for( int i = 0; i < 1005; ++i ) {
		while( cur < 10005 && dp[cur][k]+eps < (double)i/2000.0+eps ) ++cur;
		ans[i] = cur;
	}
	while(q--) {
		int p;
		cin >> p;
		cout << ans[p] << endl;
	}
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define PB push_back
#define F first
#define S second
#define MP make_pair
#define endl '\n'

const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 1000000007

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

//
//debug
template<typename F,typename S>ostream&operator<<(ostream&os,const pair<F,S>&p){return os<<"("<<p.first<<", "<<p.second<<")";}
template<typename T>ostream&operator<<(ostream&os,const vector<T>&v){os<<"{";for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin())os<<", ";os<<*it;}return os<<"}";}
template<typename T>ostream&operator<<(ostream&os,const set<T>&v){os<<"[";for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin())os<<",";os<<*it;}return os<<"]";}
template<typename T>ostream&operator<<(ostream&os,const multiset<T>&v) {os<<"[";for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin())os<<", ";os<<*it;}return os<<"]";}
template<typename F,typename S>ostream&operator<<(ostream&os,const map<F,S>&v){os<<"[";for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin())os<<", ";os<<it->first<<" = "<<it->second;}return os<<"]";}
#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)
void faltu(){cerr << endl;}
template<typename T>void faltu(T a[],int n){for(int i=0;i<n;++i)cerr<<a[i]<<' ';cerr<<endl;}
template<typename T,typename...hello>void faltu(T arg,const hello&...rest){cerr<<arg<<' ';faltu(rest...);}
//#else
//#define dbg(args...)

int k, q;
double dp[3005][1005];

int main()
{
	optimize();
	cin >> k >> q;
	dp[0][0] = 1;
	for( int day = 1; day < 3005; ++day ) {
		for( int x = 1; x <= k; ++x ) {
			dp[day][x] += ((double)x/(double)k)*dp[day-1][x] + ((double)(k-x+1)/(double)k)*dp[day-1][x-1];
		}
	}
	int cur = 0;
	while(q--) {
		int p;
		cin >> p;
		while( cur < 3005 && dp[cur][k] < (double)p/2000.0 ) ++cur;
		cout << cur << endl;
	}
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define PB push_back
#define F first
#define S second
#define MP make_pair
#define endl '\n'

const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 1000000007

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

//
//debug
template<typename F,typename S>ostream&operator<<(ostream&os,const pair<F,S>&p){return os<<"("<<p.first<<", "<<p.second<<")";}
template<typename T>ostream&operator<<(ostream&os,const vector<T>&v){os<<"{";for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin())os<<", ";os<<*it;}return os<<"}";}
template<typename T>ostream&operator<<(ostream&os,const set<T>&v){os<<"[";for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin())os<<",";os<<*it;}return os<<"]";}
template<typename T>ostream&operator<<(ostream&os,const multiset<T>&v) {os<<"[";for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin())os<<", ";os<<*it;}return os<<"]";}
template<typename F,typename S>ostream&operator<<(ostream&os,const map<F,S>&v){os<<"[";for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin())os<<", ";os<<it->first<<" = "<<it->second;}return os<<"]";}
#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)
void faltu(){cerr << endl;}
template<typename T>void faltu(T a[],int n){for(int i=0;i<n;++i)cerr<<a[i]<<' ';cerr<<endl;}
template<typename T,typename...hello>void faltu(T arg,const hello&...rest){cerr<<arg<<' ';faltu(rest...);}
//#else
//#define dbg(args...)

int k, q;
double dp[10005][1005];

int main()
{
	optimize();
	cin >> k >> q;
	dp[0][0] = 1;
	for( int day = 1; day < 10005; ++day ) {
		for( int x = 1; x <= k; ++x ) {
			dp[day][x] += ((double)x/(double)k)*dp[day-1][x] + ((double)(k-x+1)/(double)k)*dp[day-1][x-1];
		}
	}
	int cur = 0;
	while(q--) {
		int p;
		cin >> p;
		while( cur < 10005 && dp[cur][k] < (double)p/2000.0 ) ++cur;
		cout << cur << endl;
	}
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define PB push_back
#define F first
#define S second
#define MP make_pair
#define endl '\n'

const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 1000000007

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

//
//debug
template<typename F,typename S>ostream&operator<<(ostream&os,const pair<F,S>&p){return os<<"("<<p.first<<", "<<p.second<<")";}
template<typename T>ostream&operator<<(ostream&os,const vector<T>&v){os<<"{";for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin())os<<", ";os<<*it;}return os<<"}";}
template<typename T>ostream&operator<<(ostream&os,const set<T>&v){os<<"[";for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin())os<<",";os<<*it;}return os<<"]";}
template<typename T>ostream&operator<<(ostream&os,const multiset<T>&v) {os<<"[";for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin())os<<", ";os<<*it;}return os<<"]";}
template<typename F,typename S>ostream&operator<<(ostream&os,const map<F,S>&v){os<<"[";for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin())os<<", ";os<<it->first<<" = "<<it->second;}return os<<"]";}
#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)
void faltu(){cerr << endl;}
template<typename T>void faltu(T a[],int n){for(int i=0;i<n;++i)cerr<<a[i]<<' ';cerr<<endl;}
template<typename T,typename...hello>void faltu(T arg,const hello&...rest){cerr<<arg<<' ';faltu(rest...);}
//#else
//#define dbg(args...)

const double eps = 1e-7;

int k, q;
double dp[10005][1005];
int ans[1005];

int main()
{
	optimize();
	cin >> k >> q;
	dp[0][0] = 1;
	for( int day = 1; day < 10005; ++day ) {
		for( int x = 1; x <= k; ++x ) {
			dp[day][x] += ((double)x/(double)k)*dp[day-1][x] + ((double)(k-x+1)/(double)k)*dp[day-1][x-1];
		}
	}
	int cur = 0;
	for( int i = 0; i < 1005; ++i ) {
		while( cur < 10005 && dp[cur][k] < (double)i/2000.0 ) ++cur;
		ans[i] = cur;
	}
	while(q--) {
		int p;
		cin >> p;
		cout << ans[p] << endl;
	}
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define PB push_back
#define F first
#define S second
#define MP make_pair
#define endl '\n'

const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 1000000007

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

//
//debug
template<typename F,typename S>ostream&operator<<(ostream&os,const pair<F,S>&p){return os<<"("<<p.first<<", "<<p.second<<")";}
template<typename T>ostream&operator<<(ostream&os,const vector<T>&v){os<<"{";for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin())os<<", ";os<<*it;}return os<<"}";}
template<typename T>ostream&operator<<(ostream&os,const set<T>&v){os<<"[";for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin())os<<",";os<<*it;}return os<<"]";}
template<typename T>ostream&operator<<(ostream&os,const multiset<T>&v) {os<<"[";for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin())os<<", ";os<<*it;}return os<<"]";}
template<typename F,typename S>ostream&operator<<(ostream&os,const map<F,S>&v){os<<"[";for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin())os<<", ";os<<it->first<<" = "<<it->second;}return os<<"]";}
#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)
void faltu(){cerr << endl;}
template<typename T>void faltu(T a[],int n){for(int i=0;i<n;++i)cerr<<a[i]<<' ';cerr<<endl;}
template<typename T,typename...hello>void faltu(T arg,const hello&...rest){cerr<<arg<<' ';faltu(rest...);}
//#else
//#define dbg(args...)

const double eps = 1e-7;

int k, q;
double dp[10005][1005];
int ans[1005];

int main()
{
	optimize();
	cin >> k >> q;
	dp[0][0] = 1;
	for( int day = 1; day < 10005; ++day ) {
		for( int x = 1; x <= k; ++x ) {
			dp[day][x] += ((double)x/(double)k)*dp[day-1][x] + ((double)(k-x+1)/(double)k)*dp[day-1][x-1];
		}
	}
	int cur = 0;
	for( int i = 0; i < 1005; ++i ) {
		while( cur < 10005 && dp[cur][k]+eps < (double)i/2000.0 ) ++cur;
		ans[i] = cur;
	}
	while(q--) {
		int p;
		cin >> p;
		cout << ans[p] << endl;
	}
}


#include <bits/stdc++.h>
using namespace std;

vector<int> prime;
bitset<7005> smark,bad,ms[100005],s[7005],c[7005];
int in1,in2,in3,n,q;

int main()
{
    ios::sync_with_stdio(false);
    for(int i=2;i<=7000;i++)
    {
        if(smark[i])
        {
            continue;
        }
        for(int j=2*i;j<=7000;j++)
        {
            smark[j]=1;
            if(j%(i*i)==0)
            {
                bad[j]=true;
            }
        }
    }
    for(int i=1;i<=7000;i++)
    {
        for(int j=1;j<=i;j++)
        {
            if(i%j==0)
            {
                s[i][j]=1;
            }
        }
        for(int j=i;j<=7000;j+=i)
        {
            if(bad[j/i]) continue;
            c[i][j]=1;
        }
    }
    cin>>n>>q;
    while(q--)
    {
        cin>>in1;
        if(in1==1)
        {
            cin>>in1>>in2;
            ms[in1]=s[in2];
        }
        else if(in1==2)
        {
            cin>>in1>>in2>>in3;
            ms[in1]=ms[in2]^ms[in3];
        }
        else if(in1==3)
        {
            cin>>in1>>in2>>in3;
            ms[in1]=ms[in2]&ms[in3];
        }
        else
        {
            cin>>in1>>in2;
            cout<<((ms[in1]&c[in2]).count()&1);
        }
    }
}


#include <bits/stdc++.h>
using namespace std;

bitset<7001> smark,bad,ms[100001],s[7001],c[7001];
int in1,in2,in3,n,q;

int main()
{
    ios::sync_with_stdio(false);
    for(int i=2;i<=7000;i++)
    {
        if(smark[i])
        {
            continue;
        }
        for(int j=2*i;j<=7000;j+=i)
        {
            smark[j]=1;
            if(j%(i*i)==0)
            {
                bad[j]=true;
            }
        }
    }
    for(int i=1;i<=7000;i++)
    {
        for(int j=1;j<=i;j++)
        {
            if(i%j==0)
            {
                s[i][j]=1;
            }
        }
        for(int j=i;j<=7000;j+=i)
        {
            if(bad[j/i]) continue;
            c[i][j]=1;
        }
    }
    cin>>n>>q;
    while(q--)
    {
        cin>>in1;
        if(in1==1)
        {
            cin>>in1>>in2;
            ms[in1]=s[in2];
        }
        else if(in1==2)
        {
            cin>>in1>>in2>>in3;
            ms[in1]=ms[in2]^ms[in3];
        }
        else if(in1==3)
        {
            cin>>in1>>in2>>in3;
            ms[in1]=ms[in2]&ms[in3];
        }
        else
        {
            cin>>in1>>in2;
            cout<<((ms[in1]&c[in2]).count()&1);
        }
    }
}


// Phoenix

#include<bits/stdc++.h>

#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int MAX=7010,maxn=1e5+10;

bitset<MAX> tr0[MAX],tr1[MAX],a[maxn],tmp;

int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);
    for(int i=1;i<MAX;i++){
	for(int j=i;j<MAX;j+=i){
	    tr0[j][i]=1;
	}
    }
    for(int i=MAX-1;i>=1;i--){
	for(int j=i;j<MAX;j+=i)
	    tr1[i]^=tr1[j];
	tr1[i][i]=1;
    }
    int n,q;cin>>n>>q;
    while(q--){
	int task;cin>>task;
	if(task==1){
	    int x,v;cin>>x>>v;
	    a[--x]^=tr0[v];
	}
	if(task==2){
	    int x,y,z;cin>>x>>y>>z;
	    a[--x]=a[--y]^a[--z];
	}
	if(task==3){
	    int x,y,z;cin>>x>>y>>z;
	    a[--x]=a[--y]&a[--z];
	}
	if(task==4){
	    int x,v;cin>>x>>v;
	    tmp=a[--x]&tr1[v];
	    cout<<tmp.count();
	}
    }
    cout<<endl;
    return 0;
}


// Phoenix

#include<bits/stdc++.h>

#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int MAX=7010,maxn=1e5+10;

bitset<MAX> tr0[MAX],tr1[MAX],a[maxn],tmp;

int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);
    for(int i=1;i<MAX;i++){
	for(int j=i;j<MAX;j+=i){
	    tr0[j][i]=1;
	}
    }
    for(int i=MAX-1;i>=1;i--){
	for(int j=i;j<MAX;j+=i)
	    tr1[i]^=tr1[j];
	tr1[i][i]=1;
    }
    int n,q;cin>>n>>q;
    while(q--){
	int task;cin>>task;
	if(task==1){
	    int x,v;cin>>x>>v;
	    a[--x]=tr0[v];
	}
	if(task==2){
	    int x,y,z;cin>>x>>y>>z;
	    a[--x]=a[--y]^a[--z];
	}
	if(task==3){
	    int x,y,z;cin>>x>>y>>z;
	    a[--x]=a[--y]&a[--z];
	}
	if(task==4){
	    int x,v;cin>>x>>v;
	    tmp=a[--x]&tr1[v];
	    cout<<tmp.count()%2;
	}
    }
    cout<<endl;
    return 0;
}


// Phoenix

#include<bits/stdc++.h>

#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int MAX=7010,maxn=1e5+10;

bitset<MAX> tr0[MAX],tr1[MAX],a[maxn],tmp;

int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);
    for(int i=1;i<MAX;i++){
	for(int j=i;j<MAX;j+=i){
	    tr0[j][i]=1;
	}
    }
    for(int i=MAX-1;i>=1;i--){
	for(int j=i;j<MAX;j+=i)
	    tr1[i]^=tr1[j];
	tr1[i][i]=1;
    }
    int n,q;cin>>n>>q;
    while(q--){
	int task;cin>>task;
	if(task==1){
	    int x,v;cin>>x>>v;
	    a[--x]^=tr0[v];
	}
	if(task==2){
	    int x,y,z;cin>>x>>y>>z;
	    a[--x]=a[--y]^a[--z];
	}
	if(task==3){
	    int x,y,z;cin>>x>>y>>z;
	    a[--x]=a[--y]&a[--z];
	}
	if(task==4){
	    int x,v;cin>>x>>v;
	    tmp=a[--x]&tr1[v];
	    cout<<tmp.count()%2;
	}
    }
    cout<<endl;
    return 0;
}


//Be Name Khoda, Besmellah Rahmane Rahim, In The Name Of God;
//#include<bits/stdc++.h>
#include<iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <map>
#include <stack>
#include<bitset>
#include<list>
#include<cassert>
#include<numeric>
#include <stdio.h>
#include <string.h>
#include<iomanip>
#include<unordered_map>
#include<unordered_set>
#include <fstream>

using namespace std;

const int N = 100005;
const int M = 7005;
bitset<M> a[N];
bitset<M> init[M];
bitset<M> mask[M];
int n, q;
int isPrime[M];

void pre()
{
    isPrime[1] = 1;
    for (int i = 1; i < M; i++)
    {
        for (int j = i * 2; j < M; j += i)
        {
            isPrime[j] -= isPrime[i];
        }
    }
    /*
    for (int i = 0; i < 20; i++)
    {
        cout << isPrime[i] << " " << i << endl;
    }
    */
    for (int i = 1; i < M; i++)
    {
        for (int j = i; j < M; j += i)
        {
            if (isPrime[j / i])
            {
                mask[i][j] = 1;
            }
            init[j][i] = 1;
        }
    }
}
int

main ()
{
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    pre();
    cin >> n >> q;
    for (int i = 0; i < q; i++)
    {
        int c, x, y, z, v;
        cin >> c;
        if (c == 1)
        {
            cin >> x >> v;
            a[x] = init[v];
            continue;
        }
        if (c == 2)
        {
            cin >> x >> y >> z;
            a[x] = a[y] ^ a[z];
            continue;
        }
        if (c == 3)
        {
            cin >> x >> y >> z;
            a[x] = a[y] & a[z];
            continue;
        }
        if (c == 4)
        {
            cin >> x >> v;
            cout << ((a[x] & mask[v]).count() & 1);
        }
    }
}


//Be Name Khoda, Besmellah Rahmane Rahim, In The Name Of God;
//#include<bits/stdc++.h>
#include<iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <map>
#include <stack>
#include<bitset>
#include<list>
#include<cassert>
#include<numeric>
#include <stdio.h>
#include <string.h>
#include<iomanip>
#include<unordered_map>
#include<unordered_set>
#include <fstream>

using namespace std;

const int N = 100005;
const int M = 7005;
bitset<M> a[N];
bitset<M> init[M];
bitset<M> mask[M];
int n, q;
int isPrime[M];

void pre()
{
    isPrime[1] = 1;
    for (int i = 1; i < M; i++)
    {
        for (int j = i * 2; j < M; j += i)
        {
            isPrime[j] -= isPrime[i];
        }
    }
    /*
    for (int i = 0; i < 20; i++)
    {
        cout << isPrime[i] << " " << i << endl;
    }
    */
    for (int i = 1; i < M; i++)
    {
        for (int j = i; j < M; j += i)
        {
            if (isPrime[j / i])
            {
                mask[i][j] = 1;
            }
            init[j][i] = 1;
        }
    }
}
int

main ()
{
    pre();
    cin >> n >> q;
    for (int i = 0; i < q; i++)
    {
        int c, x, y, z, v;
        cin >> c;
        if (c == 1)
        {
            cin >> x >> v;
            a[x] = init[v];
            continue;
        }
        if (c == 2)
        {
            cin >> x >> y >> z;
            a[x] = a[y] ^ a[z];
            continue;
        }
        if (c == 3)
        {
            cin >> x >> y >> z;
            a[x] = a[y] & a[z];
            continue;
        }
        if (c == 4)
        {
            cin >> x >> v;
            cout << ((a[x] & mask[v]).count() & 1);
        }
    }
}


#include <iostream>
#include <stdio.h>
#include <vector>
#include <random>
#include <algorithm>
#include <set>
#include <string>
#include <sstream>
#include <cassert>
#include <map>
#include <bitset>

using namespace std;

typedef long long ll;
typedef double dbl;

template<class T>
void print(vector<T> s){
    for (auto x : s)
        cout << x << " ";
    cout << endl;
}

const int maxv = 7, maxn = 1e5 + 7;

bitset<maxv> s[maxn];
bitset<maxv> nullik;
bitset<maxv> kost[maxn];

int mu[maxv];
int smalest[maxv];
vector<int> divisors[maxv];
bool f[maxn];

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	// freopen("test.in", "r", stdin);
	int n, q;
	cin >> n >> q;
	vector<int> free;
	for (int i = 1; i < maxv; i++){
		smalest[i] = -1;
		int cur = i;
		bool ok = true;
		divisors[i].push_back(1);
		for (int j = 2; j <= i; j++){
			if (i % j == 0)
				divisors[i].push_back(j);
			if (cur % j != 0)
				continue;
			if (smalest[i] == -1)
				smalest[i] = j;
			if (cur % (j * j) == 0)
				ok = false;
			while (cur % j == 0)
				cur /= j;
		}
		if (ok)
			free.push_back(i);
	}
	for (int i = 1; i < maxv; i++){
		for (int u : free){
			if (u * i >= maxv)
				break;
			kost[i].set(i * u);
		}
	}
	while (q-- > 0){
		int t;
		cin >> t;
		if (t == 1){
			int i, v;
			cin >> i >> v;
			s[i - 1] &= nullik;
			for (int u : divisors[v])
				s[i - 1].set(u);
		}
		if (t == 2){
			int x, y, z;
			cin >> x >> y >> z;
			s[x - 1] = s[y - 1] ^ s[z - 1];
		}
		if (t == 3){
			int x, y, z;
			cin >> x >> y >> z;
			s[x - 1] = s[y - 1] & s[z - 1];
		}
		if (t == 4){
			int i, v;
			cin >> i >> v;
			cout << ((s[i - 1] & kost[v]).count() & 1);
		}
	}
	cout << endl;
	return 0;
}


#include <iostream>
#include <stdio.h>
#include <vector>
#include <random>
#include <algorithm>
#include <set>
#include <string>
#include <sstream>
#include <cassert>
#include <map>
#include <bitset>

using namespace std;

typedef long long ll;
typedef double dbl;

template<class T>
void print(vector<T> s){
    for (auto x : s)
        cout << x << " ";
    cout << endl;
}

const int maxv = 7007, maxn = 1e5 + 7;

bitset<maxv> s[maxn];
bitset<maxv> nullik;
bitset<maxv> kost[maxn];

int mu[maxv];
int smalest[maxv];
vector<int> divisors[maxv];
bool f[maxn];

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	// freopen("test.in", "r", stdin);
	int n, q;
	cin >> n >> q;
	vector<int> free;
	for (int i = 1; i < maxv; i++){
		smalest[i] = -1;
		int cur = i;
		bool ok = true;
		divisors[i].push_back(1);
		for (int j = 2; j <= i; j++){
			if (i % j == 0)
				divisors[i].push_back(j);
			if (cur % j != 0)
				continue;
			if (smalest[i] == -1)
				smalest[i] = j;
			if (cur % (j * j) == 0)
				ok = false;
			while (cur % j == 0)
				cur /= j;
		}
		if (ok)
			free.push_back(i);
	}
	for (int i = 1; i < maxv; i++){
		for (int u : free){
			if (u * i >= maxv)
				break;
			kost[i].set(i * u);
		}
	}
	while (q-- > 0){
		int t;
		cin >> t;
		if (t == 1){
			int i, v;
			cin >> i >> v;
			s[i - 1] &= nullik;
			for (int u : divisors[v])
				s[i - 1].set(u);
		}
		if (t == 2){
			int x, y, z;
			cin >> x >> y >> z;
			s[x - 1] = s[y - 1] ^ s[z - 1];
		}
		if (t == 3){
			int x, y, z;
			cin >> x >> y >> z;
			s[x - 1] = s[y - 1] & s[z - 1];
		}
		if (t == 4){
			int i, v;
			cin >> i >> v;
			cout << ((s[i - 1] & kost[v]).count() & 1);
		}
	}
	cout << endl;
	return 0;
}


#include <iostream>
#include <stdio.h>
#include <vector>
#include <random>
#include <algorithm>
#include <set>
#include <string>
#include <sstream>
#include <cassert>
#include <map>
#include <bitset>

using namespace std;

typedef long long ll;
typedef double dbl;

template<class T>
void print(vector<T> s){
    for (auto x : s)
        cout << x << " ";
    cout << endl;
}

const int maxv = 7007, maxn = 1e5 + 7;

bitset<maxv> s[maxn];
bitset<maxv> nullik;

int mu[maxv];
int smalest[maxv];
vector<int> divisors[maxv];

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	// freopen("test.in", "r", stdin);
	int n, q;
	cin >> n >> q;
	vector<int> free;
	for (int i = 1; i < maxv; i++){
		smalest[i] = -1;
		int cur = i;
		bool ok = true;
		divisors[i].push_back(1);
		for (int j = 2; j <= i; j++){
			if (i % j == 0)
				divisors[i].push_back(j);
			if (cur % j != 0)
				continue;
			if (smalest[i] == -1)
				smalest[i] = j;
			if (cur % (j * j) == 0)
				ok = false;
			while (cur % j == 0)
				cur /= j;
		}
		if (ok)
			free.push_back(i);
	}
	while (q-- > 0){
		int t;
		cin >> t;
		if (t == 1){
			int i, v;
			cin >> i >> v;
			s[i - 1] &= nullik;
			for (int u : divisors[v])
				s[i - 1].set(u);
		}
		if (t == 2){
			int x, y, z;
			cin >> x >> y >> z;
			s[x - 1] = s[y - 1] ^ s[z - 1];
		}
		if (t == 3){
			int x, y, z;
			cin >> x >> y >> z;
			s[x - 1] = s[y - 1] & s[z - 1];
		}
		if (t == 4){
			int i, v;
			cin >> i >> v;
			int answer = 0;
			for (int u : free){
				if (u * v >= maxv)
					break;
				answer ^= s[i - 1].test(v * u);
			}
			cout << answer;
		}
	}
	cout << endl;
	return 0;
}


#include <sstream>
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<ctime>
#include<cmath>
#include<map>
#include<stack>
#include<random>
#include<queue>
#include<list>
#include<math.h>
#include<bitset>
using namespace std;
#define ll long long int
#define ld long double
#define key pair<ld,ld>
#define ii pair<int,int>
#define si set<int>
#define vii vector<pair<int,int> >
#define vi vector<int>
#define vll vector<ll>
#define vb vector<bool>
#define vvi vector<vector<int> >
#define vs vector<string>
#define all(v) v.begin(),v.end()
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define nu 100001
#define mod 1000000007
#define mul(x,y) ((ll)(x)*(y))%mod
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)
#define fastio  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define forn(i, n) for (int i = 0; i < int(n); i++)
const ll INF=9223372036854775807;
//const ll mod=998244353;
int  MOD(int  a, int  b)
{
    if(a>b)
        return a-b;
    else
        return b-a;
}
int  max3(int  a,int  b, int  c)
{
    return max(c,max(a,b));
}
int  min3(int  a,int  b,int  c)
{
    return min(a,min(b,c));
}
ll  power(ll  x,ll  y )
{
    ll res = 1;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x)%mod;
        y = y>>1;
        x = (x*x)%mod;
    }
    return res%mod;
}
ll logg(ll  a)
{
    ll  x=0;
    while(a>1)
    {
        x++;
        a/=2;
    }
    return x;
}
ll  gcd(ll  a,ll   b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
ll abso(ll x)
{
    if(x<0)
    {
        return -x;
    }
    return x;
}
ll ceiling (ll  a,ll  b)
{
    if(a%b==0)
    {
        return a/b;
    }
    else
    {
        return a/b+1;
    }
}
ll modinv(ll x)
{
    return power(x,mod-2);
}
int MAXN=100002;
int vmax=7001;
vector<bitset<7001>> a(MAXN);
int main()
{
    fastio;
    int n,q;
    cin>>n>>q;
    bitset<7001> mu;
    mu.set();
    vi iscomp(7001);
    for(int i=2;i<=7000;i++)
    {
        if(!iscomp[i])
        {
            for(int j=2*i;j<=7000;j+=i)
            {
                iscomp[i]=1;
            }
            for(int j=2*i;j<=7000;j+=i)
            {
                if(j%(i*i)==0)
                {
                    mu[j]=0;
                }
            }
        }
    }
    vector<bitset<7001>> v(7001);
    for(int i=1;i<=7000;i++)
    {
        for(int j=i;j<=7000;j+=i)
        {
            v[j][i]=1;
        }
    }
    vector<bitset<7001>> mu_vec(7001);
    for(int i=1;i<=7000;i++)
    {
        for(int j=i;j<=7000;j+=i)
        {
            if(mu[j/i]==1)
            {
                mu_vec[i][j]=1;
            }
        }
    }
    while(q--)
    {
        int ch;
        cin>>ch;
        if(ch==1)
        {
            int x,y;
            cin>>x>>y;
            a[x]=v[y];
        }
        if(ch==2)
        {
            int x,y,z;
            cin>>x>>y>>z;
            a[x]=a[y]^a[z];
        }
        if(ch==3)
        {
            int x,y,z;
            cin>>x>>y>>z;
            a[x]=a[y]&a[z];
        }
        if(ch==4)
        {
            int x,y;
            cin>>x>>y;
            int ans=0;
            /*for(int i=y;i<=7000;i+=y)
            {
                if(mu[i/y]==1)
                {
                    if(a[x][i]==1)
                    {
                        ans++;
                    }
                }
            }*/

            cout<<(a[x]&mu_vec[y]).count()%2;
        }
    }
}


#include <sstream>
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<ctime>
#include<cmath>
#include<map>
#include<stack>
#include<random>
#include<queue>
#include<list>
#include<math.h>
#include<bitset>
using namespace std;
#define ll long long int
#define ld long double
#define key pair<ld,ld>
#define ii pair<int,int>
#define si set<int>
#define vii vector<pair<int,int> >
#define vi vector<int>
#define vll vector<ll>
#define vb vector<bool>
#define vvi vector<vector<int> >
#define vs vector<string>
#define all(v) v.begin(),v.end()
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define nu 100001
#define mod 1000000007
#define mul(x,y) ((ll)(x)*(y))%mod
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)
#define fastio  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define forn(i, n) for (int i = 0; i < int(n); i++)
const ll INF=9223372036854775807;
//const ll mod=998244353;
int  MOD(int  a, int  b)
{
    if(a>b)
        return a-b;
    else
        return b-a;
}
int  max3(int  a,int  b, int  c)
{
    return max(c,max(a,b));
}
int  min3(int  a,int  b,int  c)
{
    return min(a,min(b,c));
}
ll  power(ll  x,ll  y )
{
    ll res = 1;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x)%mod;
        y = y>>1;
        x = (x*x)%mod;
    }
    return res%mod;
}
ll logg(ll  a)
{
    ll  x=0;
    while(a>1)
    {
        x++;
        a/=2;
    }
    return x;
}
ll  gcd(ll  a,ll   b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
ll abso(ll x)
{
    if(x<0)
    {
        return -x;
    }
    return x;
}
ll ceiling (ll  a,ll  b)
{
    if(a%b==0)
    {
        return a/b;
    }
    else
    {
        return a/b+1;
    }
}
ll modinv(ll x)
{
    return power(x,mod-2);
}
int MAXN=100002;
int vmax=7001;
vector<bitset<7001>> a(MAXN);
int main()
{
    fastio;
    int n,q;
    cin>>n>>q;
    bitset<7001> mu;
    mu.set();
    vi iscomp(7001);
    for(int i=2;i<=7000;i++)
    {
        if(!iscomp[i])
        {
            for(int j=2*i;j<=7000;j+=i)
            {
                iscomp[i]=1;
            }
            for(int j=2*i;j<=7000;j+=i)
            {
                if(j%(i*i)==0)
                {
                    mu[j]=0;
                }
            }
        }
    }
    while(q--)
    {
        int ch;
        cin>>ch;
        if(ch==1)
        {
            int x,y;
            cin>>x>>y;
            a[x].reset();
            for(int i=1;i*i<=y;i++)
            {
                if(y%i==0)
                {
                    a[x][i]=1;
                    if(i!=y/i)
                    {
                        a[x][y/i]=1;
                    }
                }
            }
        }
        if(ch==2)
        {
            int x,y,z;
            cin>>x>>y>>z;
            a[x]=a[y]^a[z];
        }
        if(ch==3)
        {
            int x,y,z;
            cin>>x>>y>>z;
            a[x]=a[y]&a[z];
        }
        if(ch==4)
        {
            int x,y;
            cin>>x>>y;
            int ans=0;
            for(int i=y;i<=7000;i+=y)
            {
                if(mu[i/y]==1)
                {
                    if(a[x][i]==1)
                    {
                        ans++;
                    }
                }
            }
            cout<<ans%2;
        }
    }
}


#include <set>
#include <cstdio>
#include <vector>
#include <cassert>
#include <cstdlib>
#include <cstring>
using namespace std;

typedef unsigned long long mask_t;

const int kMaxV = 7002;
const int kMaxN = 100010;

struct MySet {
  void clear() {
    memset(num_multipliers, 0, sizeof num_multipliers);
  }

  void set(int i) {
    num_multipliers[i / 64] ^= ((mask_t)1 << (i % 64));
  }

  int get(int i) const {
    assert(i < kMaxV);
    return !!(num_multipliers[i / 64] & ((mask_t)1 << (i % 64)));
  }

  int parity() const {
    mask_t agg = 0;
    for (int i = 0; i < 1 + kMaxV / 64; ++i) {
      agg ^= num_multipliers[i];
    }
    int sol = 0;
    for (; agg; agg>>=1) {
      sol += (agg & 1);
    }
    return sol % 2;
  }

  mask_t num_multipliers[1 + kMaxV / 64];
};

MySet singleton[kMaxV];
MySet output[kMaxV];
MySet sets[kMaxN];
MySet result;

void init_singletons() {
  for (int x = 1; x < kMaxV; ++x) {
    for (int i = 1; i <= x; ++i) {
      if (x % i == 0) {
        singleton[x].set(i);
      }
    }
  }
}

bool is_square_free(int x) {
  for (int j = 2; j * j <= x; ++j) {
    if (x % (j * j) == 0) {
      return false;
    }
  }
  return true;
}

void init_outputs() {
  for (int x = 1; x < kMaxV; ++x) {
    output[x].set(x);
    for (int j = 2; x * j < kMaxV; j++) {
      if (is_square_free(j)) {
        output[x].set(x * j);
      }
    }
  }
}

void bitwise_xor(const MySet& a, const MySet& b, MySet *out) {
  for (int i = 0; i < kMaxV / 64; ++i) {
    out->num_multipliers[i] = a.num_multipliers[i] ^ b.num_multipliers[i];
  }
}

void bitwise_and(const MySet& a, const MySet& b, MySet *out) {
  for (int i = 0; i < kMaxV / 64; ++i) {
    out->num_multipliers[i] = a.num_multipliers[i] & b.num_multipliers[i];
  }
}

int main() {
  init_singletons();
  init_outputs();

  int n, q;
  scanf("%d%d", &n, &q);
  for (int i = 0; i < q; ++i) {
    int type, x, y, z, v;
    scanf("%d", &type);
    switch (type) {
      case 1:
        scanf("%d%d", &x, &v);
        sets[x] = singleton[v];
        break;
      case 2:
        scanf("%d%d%d", &x, &y, &z);
        bitwise_xor(sets[y], sets[z], &sets[x]);
        break;
      case 3:
        scanf("%d%d%d", &x, &y, &z);
        bitwise_and(sets[y], sets[z], &sets[x]);
        break;
      case 4:
        scanf("%d%d", &x, &v);
        result.clear();
        bitwise_and(sets[x], output[v], &result);
        printf("%d", result.parity());
        break;
    }
  }
  printf("\n");

  return 0;
}


#include <set>
#include <cstdio>
#include <vector>
#include <cassert>
#include <cstdlib>
#include <cstring>
using namespace std;

typedef unsigned long long mask_t;

const int kMaxV = 7002;
const int kMaxN = 100010;

struct MySet {
  void set(int i) {
    num_multipliers[i / 64] ^= ((mask_t)1 << (i % 64));
  }

  int get(int i) const {
    assert(i < kMaxV);
    return !!(num_multipliers[i / 64] & ((mask_t)1 << (i % 64)));
  }

  int parity() const {
    mask_t agg = 0;
    for (int i = 0; i < 1 + kMaxV / 64; ++i) {
      agg ^= num_multipliers[i];
    }
    int sol = 0;
    for (; agg; agg>>=1) {
      sol += (agg & 1);
    }
    return sol % 2;
  }

  mask_t num_multipliers[1 + kMaxV / 64];
};

MySet singleton[kMaxV];
MySet output[kMaxV];
MySet sets[kMaxN];

void init_singletons() {
  for (int x = 1; x < kMaxV; ++x) {
    for (int i = 1; i <= x; ++i) {
      if (x % i == 0) {
        singleton[x].set(i);
      }
    }
  }
}

bool is_square_free(int x) {
  for (int j = 2; j * j <= x; ++j) {
    if (x % (j * j) == 0) {
      return false;
    }
  }
  return true;
}

void init_outputs() {
  for (int x = 1; x < kMaxV; ++x) {
    output[x].set(x);
    for (int j = 2; x * j < kMaxV; j++) {
      if (is_square_free(j)) {
        output[x].set(x * j);
      }
    }
  }
}

void bitwise_xor(const MySet& a, const MySet& b, MySet *out) {
  for (int i = 0; i < kMaxV / 64; ++i) {
    out->num_multipliers[i] = a.num_multipliers[i] ^ b.num_multipliers[i];
  }
}

void bitwise_and(const MySet& a, const MySet& b, MySet *out) {
  for (int i = 0; i < kMaxV / 64; ++i) {
    out->num_multipliers[i] = a.num_multipliers[i] & b.num_multipliers[i];
  }
}

int main() {
  init_singletons();
  init_outputs();

  int n, q;
  scanf("%d%d", &n, &q);
  for (int i = 0; i < q; ++i) {
    int type, x, y, z, v;
    scanf("%d", &type);
    switch (type) {
      case 1:
        scanf("%d%d", &x, &v);
        sets[x] = singleton[v];
        break;
      case 2:
        scanf("%d%d%d", &x, &y, &z);
        bitwise_xor(sets[y], sets[z], &sets[x]);
        break;
      case 3:
        scanf("%d%d%d", &x, &y, &z);
        bitwise_and(sets[y], sets[z], &sets[x]);
        break;
      case 4:
        scanf("%d%d", &x, &v);
        MySet result;
        bitwise_and(sets[x], output[v], &result);
        printf("%d", result.parity());
        break;
    }
  }
  printf("\n");

  return 0;
}


#include <set>
#include <cstdio>
#include <vector>
#include <cassert>
#include <cstdlib>
#include <cstring>
using namespace std;

typedef unsigned long long mask_t;

const int kMaxV = 7002;
const int kMaxVbits = 7002 / 64 + 1;
const int kMaxN = 100010;

struct MySet {
  void clear() {
    memset(num_multipliers, 0, sizeof num_multipliers);
  }

  void set(int i) {
    num_multipliers[i / 64] ^= ((mask_t)1 << (i % 64));
  }

  int get(int i) const {
    return !!(num_multipliers[i / 64] & ((mask_t)1 << (i % 64)));
  }

  int parity() const {
    mask_t agg = 0;
    for (int i = 0; i < kMaxVbits; ++i) {
      agg ^= num_multipliers[i];
    }
    int sol = 0;
    for (; agg; agg>>=1) {
      sol += (agg & 1);
    }
    return sol % 2;
  }

  mask_t num_multipliers[kMaxVbits];
};

MySet singleton[kMaxV];
MySet output[kMaxV];
MySet sets[kMaxN];
MySet result;

void init_singletons() {
  for (int x = 1; x < kMaxV; ++x) {
    for (int i = 1; i <= x; ++i) {
      if (x % i == 0) {
        singleton[x].set(i);
      }
    }
  }
}

bool is_square_free(int x) {
  for (int j = 2; j * j <= x; ++j) {
    if (x % (j * j) == 0) {
      return false;
    }
  }
  return true;
}

void init_outputs() {
  for (int x = 1; x < kMaxV; ++x) {
    output[x].set(x);
    for (int j = 2; x * j < kMaxV; j++) {
      if (is_square_free(j)) {
        output[x].set(x * j);
      }
    }
  }
}

void bitwise_xor(const MySet& a, const MySet& b, MySet *out) {
  for (int i = 0; i < kMaxVbits; ++i) {
    out->num_multipliers[i] = a.num_multipliers[i] ^ b.num_multipliers[i];
  }
}

void bitwise_and(const MySet& a, const MySet& b, MySet *out) {
  for (int i = 0; i < kMaxVbits; ++i) {
    out->num_multipliers[i] = a.num_multipliers[i] & b.num_multipliers[i];
  }
}

int main() {
  init_singletons();
  init_outputs();

  int n, q;
  scanf("%d%d", &n, &q);
  for (int i = 0; i < q; ++i) {
    int type, x, y, z, v;
    scanf("%d", &type);
    switch (type) {
      case 1:
        scanf("%d%d", &x, &v);
        sets[x] = singleton[v];
        break;
      case 2:
        scanf("%d%d%d", &x, &y, &z);
        bitwise_xor(sets[y], sets[z], &sets[x]);
        break;
      case 3:
        scanf("%d%d%d", &x, &y, &z);
        bitwise_and(sets[y], sets[z], &sets[x]);
        break;
      case 4:
        scanf("%d%d", &x, &v);
        result.clear();
        bitwise_and(sets[x], output[v], &result);
        printf("%d", result.parity());
        break;
    }
  }
  printf("\n");

  return 0;
}