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
#include <bits/stdc++.h>
#include "dzilib.h"

#define ll long long
#define ld long double
#define endl '\n'
#define st first
#define nd second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;
int inf=1000000007;
ll infl=1000000000000000007;
ll mod=1000000007;
ll mod1=998244353;

const int N=1000007;

int d[4*N];
bool p[4*N];
vector<int>V[N];

ll t,n,q,c;

void prep(int k)
{
	for(int i=1;i<=k;i++) d[i]=1;
    for(int i=2;i<=k;i++)
    {
		if(p[i]) continue;
		d[i]=2;
		for(int j=2*i;j<=k;j+=i)
		{
			int x=j,ile=0;
			while(x%i==0)
			{
				x/=i;
				ile++;
			}
			d[j]*=ile+1;
			p[j]=1;
		}
	}
}

void c1()
{
	for(int i=1;i<=n;i++) V[d[i]].pb(i);
    while(t--)
    {
		int x=Ask(0);
		vector<int>cnd=V[x];
		while(sz(cnd)>1)
		{
			int y=rand()%(3*n)+1;
			x=Ask(y);
			vector<int>ncnd;
			for(auto i:cnd) if(d[i+y]==x) ncnd.pb(i);
			cnd=ncnd;
		}
		Answer(cnd[0]);
	}
}

void c2()
{
	while(t--)
	{
	vector<int>primes={0,5,7,11,13,17,19,23};
	vector<int>checks={0,4,4,4,3,3,3,2,2,2};
	ll y=rand()%1234567;
	for(int i=1;i<sz(primes);i++)
	{
		while(true)
		{
			y+=(ll)(1LL<<primes[i-1]);
			if(Ask(y)%primes[i]==0)
			{
				bool ok=1;
				ll xd=0;
				for(int l=1;l<=checks[i];l++)
				{
					xd+=(rand()%10+1);
					if(Ask(y+xd*(1LL<<primes[i]))%primes[i]!=0) ok=0;
				}
				if(ok) 
				{
					if(i!=sz(primes)-1) y+=(1LL<<(primes[i]-1));
					break;
				}
			}
		}
	}
	vector<int>cnd;
	for(ll i=1;i*(1LL<<(primes.back()-1))<=n+y;i+=2) cnd.pb(i);
	int xd=0;
	while(sz(cnd)>1)
	{
		xd++;
		ll w=rand()%10000+1;
		int x=Ask(y+w*(1LL<<primes.back()));
		x/=primes.back();
		vector<int>ncnd;
		for(auto i:cnd) if(d[i+2*w]==x) ncnd.pb(i);
		cnd=ncnd;
	}
	Answer((ll)cnd[0]*(1LL<<(primes.back()-1))-y);
	
	}
}

void c3()
{
	while(t--)
	{
		
	vector<int>primes={0,5,7,11,13,17,19,23,29,31};
	vector<int>checks={0,3,3,2,2,1,1,1,0,0};
	ll y=rand()%1234567;
	for(int i=1;i<sz(primes);i++)
	{
		while(true)
		{
			y+=(ll)(1LL<<primes[i-1]);
			if(Ask(y)%primes[i]==0)
			{
				bool ok=1;
				ll xd=0;
				for(int l=1;l<=checks[i];l++)
				{
					xd+=(rand()%10+1);
					if(Ask(y+xd*(1LL<<primes[i]))%primes[i]!=0) ok=0;
				}
				if(ok) 
				{
					if(i!=sz(primes)-1) y+=(1LL<<(primes[i]-1));
					break;
				}
			}
		}
	}
	vector<int>cnd;
	for(ll i=1;i*(1LL<<(primes.back()-1))<=n+y;i+=2) cnd.pb(i);
	int xd=0;
	while(sz(cnd)>1)
	{
		xd++;
		ll w=rand()%1000000+1;
		int x=Ask(y+w*(1LL<<primes.back()));
		x/=primes.back();
		vector<int>ncnd;
		for(auto i:cnd) if(d[i+2*w]==x) ncnd.pb(i);
		cnd=ncnd;
	}
	Answer((ll)cnd[0]*(1LL<<(primes.back()-1))-y);
	
	}
}


signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    srand(time(NULL));
    t=GetT(),n=GetN(),q=GetQ(),c=GetC();
    prep(4000000);
    if(n<=1000000) c1();
    else if(n<=1000000000) c2();
    else c3();
    
    
	
    return 0;
}