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

long long sito[1000109], cnt[1000109];
long long t, q, c, n;
vector<int> v, val[1009];
long long tab[4];

void smalln()
{
	int num, dz, cn, d, a, b, c;
	for(int i=2; i<=1020; i++) if(sito[i] == 0) for(int j=i; j<=1000100; j+=i) sito[j] = i;
	cnt[1] = 1;
	val[1].push_back(1);
	for(int i=2; i<=1000100; i++)
	{
		num = i;
		if(sito[i] == 0) sito[i] = i;
		dz = sito[i];
		cn = 1;
		d = 1;
		while(num > 1)
		{
			num /= dz;
			if(sito[num] != dz)
			{
				d *= (cn + 1);
				dz = sito[num];
				cn = 1;
			}
			else cn++;
		}
		cnt[i] = d;
		val[d].push_back(i);
	}
	while(t--)
	{
		v.clear();
		for(int i=0; i<20; i++)
		{
			a = Ask(i);
			v.push_back(a);
		}
		for(int i=0; i<val[v[0]].size(); i++)
		{
			a = 1;
			b = val[v[0]][i];
			for(int j=0; j<20; j++)
			{
				if(v[j] != cnt[b+j])
				{
					a = 0;
					break;
				}
			}
			if(a == 1)
			{
				Answer(b);
				break;
			}
		}
	}
	return;
}

void bign()
{
	long long wyk, d;
	if(n == 1000000000) wyk = 30;
	else wyk = 47;
	d = (1LL<<wyk);
	while(t--)
	{
		long long k = 0, cnt = 4, y = 0, a, b;
		tab[0] = tab[1] = tab[2] = tab[3] = 1;
		a = Ask(0);
		if(a == 1)
		{
			Answer(1);
			continue;
		}
		b = Ask(1);
		if(a == 2 && b == 2)
		{
			Answer(2);
			continue;
		}
		while(cnt > 1)
		{
			a = Ask(y);
			if(a % 2 != 0 || a == 2)
			{
				if(tab[y%4] != 0) cnt--;
				tab[y%4] = 0;
			} 
			y++;
		}
		for(int i=0; i<4; i++)
		{
			if(tab[i] == 1)
			{
				k = i + 2;
				break;
			}
		}
		for(long long i=2; i<wyk; i++)
		{
			a = k;
			y = (1LL<<i);
			while(true)
			{
				b = Ask(a);
				if(b % (i + 1) != 0)
				{
					k = a;
					break;
				}
				b = a;
				a += y;
			}
		}
		Answer(d - k);
	}
	return;
}

int main()
{
	t = GetT();
	q = GetQ();
	c = GetC();
	n = GetN();
	if(n <= 1000000) smalln();
	else bign();
	return 0;
}