1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#include <bits/stdc++.h>

#include "dzilib.h"

using namespace std;

//#define endl '\n'
#define L long long
#define MP make_pair
#define REP(i, n) for(int i = 0; i < n; ++i)
#define REPR(i, n) for(int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define FORR(i, a, b) for(int i = b - 1; i >= a; --i)
#define EB emplace_back
#define ST first
#define ND second
#define S size
#define RS resize

//template<class T> using P = pair<T, T>;
template<class T> using V = vector<T>;

const int Z = 2100000;
const int N6 = 1010000;
const int N9 = 1010000000;
const L P = 1001;
const L M1 = 1000696969;
const L M2 = 1000000007;

V<bool> is_prime;
V<int> primes;
V<L> h1, pows1;
V<L> h2, pows2;
unordered_map<L, int> hmap;

bool miller_rabin_int(L x, L n) {
    if (x >= n) return false;

    L d = 1, y, l = n - 1LL;
    int t = 0; 
    while (!(l & 1LL)) {
        t++;
        l >>= 1;
    }

    for (; l > 0LL || t--; l >>= 1) {
        if (l & 1LL) d = (d * x) % n;
        if (!l) {
            x = d;
            l = -1;
        }
        y = (x * x) % n;
        if (y == 1LL && x != 1LL && x != n - 1LL) return true;
        x = y;
    }

    return x != 1LL;
}

bool is_prime_int(int x) {
    if (x < 2) return false;

    static V<L> a = {2, 3, 5, 7};
    for (L y : a) {
        if (miller_rabin_int(y, x)) return false;
    }

    return true;
}

int divs3(int a) {
    int ans = 1;
    for (int p : primes) {
        if (p * p * p > a) {
            break;
        }
        int cnt = 1;
        while (a % p == 0) {
            a /= p;
            cnt++;
        }
        ans *= cnt;
    }
    bool is_p = a < Z ? is_prime[a] : is_prime_int(a);
    if (is_p) {
        ans <<= 1;
    } else if (int r = (int)sqrt(a); is_prime[r] && r * r == a) {
        ans *= 3;
    } else if (a != 1) {
        ans <<= 2;
    }
    return ans;
}

L get_hash1(int l, int r) {
    return (h1[r] - h1[l - 1] * pows1[r - l + 1] + M1 * M1) % M1;
}

L get_hash2(int l, int r) {
    return (h2[r] - h2[l - 1] * pows2[r - l + 1] + M2 * M2) % M2;
}

void solve2() {
    L hx1 = 0, hx2 = 0;
    static const int W = (int)1e6;
    FOR(y, W, W + 20) {
        L d = Ask(y);
        hx1 = (hx1 * P + d) % M1;
        hx2 = (hx2 * P + d) % M2;
    }
    Answer(hmap[(hx1 << 32LL) + hx2]);
}

void solve3() {
    V<L> hx1(5001), hx2(5001);
    static const int W = (int)1e7;
    FOR(y, 1, 5001) {
        L d = Ask(y + W - 1);
        hx1[y] = (hx1[y - 1] * P + d) % M1;
        hx2[y] = (hx2[y - 1] * P + d) % M2;
    }
    FOR(i, 1, 4978) {
        L w1 = (hx1[i + 19] - hx1[i - 1] * pows1[20] + M1 * M1) % M1;
        L w2 = (hx2[i + 19] - hx2[i - 1] * pows2[20] + M2 * M2) % M2;
        auto it = hmap.find((w1 << 32LL) + w2);
        if (it != hmap.end()) {
            Answer(it->second - i + 1);
            return;
        }
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    is_prime.RS(Z + 1, true);
    is_prime[0] = is_prime[1] = false;
    for (int i = 2; i * i <= Z; i++) {
        if (is_prime[i]) {
            for (int j = i * i; j <= Z; j += i) {
                is_prime[j] = false;
            }
        }
    }
    FOR(i, 1, Z + 1) {
        if (is_prime[i]) {
            primes.EB(i);
        }
    }

    pows1.RS(N6);
    pows2.RS(N6);
    pows1[0] = pows2[0] = 1;
    FOR(i, 1, N6) {
        pows1[i] = (pows1[i - 1] * P) % M1;
        pows2[i] = (pows2[i - 1] * P) % M2;
    }

    int t = GetT();
    L n = GetN();
    if (n <= (L)N6) {
        h1.RS(N6);
        h2.RS(N6);
        
        FOR(i, 1, N6) {
            L d = divs3((int)1e6 + i);
            h1[i] = (h1[i - 1] * P + d) % M1;
            h2[i] = (h2[i - 1] * P + d) % M2;
        }
        FOR(i, 1, 1000001) {
            hmap[(get_hash1(i, i + 19) << 32LL) + get_hash2(i, i + 19)] = i;
        }

        REP(i, t) {
            solve2();
        }
    } else {
        for(int i = 1; i <= N9; i += 4940) {
            L hx1 = 0, hx2 = 0;
            FOR(j, i, i + 20) {
                L d = divs3(j + (int)1e7);
                hx1 = (hx1 * P + d) % M1;
                hx2 = (hx2 * P + d) % M2;
            }
            hmap[(hx1 << 32LL) + hx2] = i;
        }

        REP(i, t) {
            solve3();
        }
    }
}