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
// #define TESTY
//
#ifndef __SIZEOF_INT128__
  #define __SIZEOF_INT128__
#endif
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace chrono;
using namespace __gnu_pbds;
template <typename T> using oset =  tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define rep(i, p, k) for(int i(p); i < (k); ++i)
#define per(i, p, k) for(int i(p); i > (k); --i)
#define sz(x) (int)(x).size()
#define sc static_cast
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef __int128_t lll;
//#define int ll
template <typename T = int> using par = std::pair <T, T>;
#define fi first
#define se second
#define test int _number_of_tests(in()); while(_number_of_tests--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb emplace_back
struct Timer {
    string name{""};
    time_point<high_resolution_clock> end, start{high_resolution_clock::now()};
    duration<float, std::milli> dur;
    Timer() = default;
    Timer(string nm): name(nm) {}
    ~Timer() {
        end = high_resolution_clock::now(); dur= end - start;
        cout << "@" << name << "> " << dur.count() << " ms" << '\n';
    }
};
template <typename T = int> inline T in()
{
    static T x;
    std::cin >> x;
    return x;
}
std::string yn(bool b)
{
    if(b) return "YES\n";
    else return "NO\n";
}
template <typename F, typename S> std::ostream& operator<<(std::ostream& out, const std::pair <F, S>& par);
template <typename T> std::ostream& operator<< (std::ostream& out, const std::vector <T>& wek)
{
    for(const auto& i : wek)out << i << ' ';
    return out;
}
template <typename F, typename S> std::ostream& operator<<(std::ostream& out, const std::pair <F, S>& par)
{
    out << '{'<<par.first<<", "<<par.second<<"}";
    return out;
}
#define show(x) cerr << #x << " = " << x << '\n';
int D(ll n){
    int i(1);
    int o(0);
    while(1ll*i*i < n){
        if(n % i == 0)o += 2;
        ++i;
    }
    return o + (1ll*i*i == n);
}
#ifdef TESTY
namespace lib
{
    int t=0, q;
    int z;
    ll n, x, c;
    int rp=0;
    void init(int s){
        if(t != rp){
            cout << "Za malo odpowiedzi\n";
            exit(5);
        }
        if(s < 0 || s > 10){
            cout << "Niepoprawny case\n";
            exit(-2);
        }
        t = s<3 ? 50 : 10;
        c = s<4 ? 1e12 : 1e17;
        if(s==1)     n=1e5;
        else if(s==2)n=1e6;
        else if(s==3)n=1e9;
        else         n=1e14;
        if(s==1)     q=5e4;
        else if(s==2)q=5e3;
        else if(s==3)q=5e4;
        else if(s==4)q=5e3;
        else if(s==5)q=2000;
        else if(s==6)q=1300;
        else if(s==7)q=950;
        else if(s==8)q=820;
        else if(s==9)q=750;
        else if(s==10)q=720;
        x = rand()%n+1;
        rp = 0;
        z = 0;
    }
}
int GetT(){return lib::t;}
ll GetN(){return lib::n;}
int GetQ(){return lib::q;}
ll GetC(){return lib::c;}
int Ask(ll y){
    if(lib::rp == lib::t){
        cout << "Dzialanie po zakonczeniu\n";
        exit(4);
    }
    if(y < 0 || y > lib::c){
        cout << "x = " << lib::x << '\n';
        cout << "Ask(" << y << "): niepoprawne y\n";
        exit(1);
    }
    if(++lib::z > lib::q){
        cout << "x = " << lib::x << '\n';
        cout << "Przekroczono limit zapytań " << lib::q << '\n';
        exit(2);
    }
    return D(lib::x+y);
}
void Answer(ll z){
    if(lib::rp == lib::t){
        cout << "Dzialanie po zakonczeniu\n";
        exit(4);
    }
    if(z != lib::x){
        cout << "Niepoprawny wynik " << z << " != " << lib::x << '\n';
        exit(3);
    }
    ++lib::rp;
    if(lib::rp == lib::t) cout << "OK\n";
    else lib::x = rand()%lib::n+1;
}
#else
#include "dzilib.h"
#endif
constexpr int MAXN = 1e6 + 20;
int d[MAXN];
std::int32_t main()
{
    rep(i, 1, MAXN)for(int j(i); j < MAXN; j += i)++d[j];
#ifdef TESTY
    int cas(in());
    srand(time(0));
    while(1){
        lib::init(cas);
        Timer tim("tim");
#endif
        int t(GetT()), q(GetQ());
        ll n(GetN()), c(GetC());
        if(n <= int(1e6)){
            map <vector <int>, int> mapa;
            int s(17);
            rep(i, 1, n+1){
                vector <int> v;
                rep(j, 0, s)v.pb(d[i+j]);
                mapa[v] = i;
            }
            rep(i, 0, t){
                vector <int> v(s);
                rep(j, 0, s)v[j] = Ask(j);
                Answer(mapa[v]);
            }
        }
        else if(n <= int(1e9)){
            rep(x, 0, t){
                int o(0);
                rep(i, 0, 31){
                    ll s[2]{0, 0};
                    rep(j, 0, 300)s[j % 2] += Ask((1ll << 31) - o + (ll(j) << i));
                    if(s[1] > s[0])o += 1<<i;
                }
                Answer(o);
            }
        }
#ifdef TESTY
    }
#endif
    return 0;
}