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
#include "dzilib.h"

#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;

const int C = 100;

int adv(int i) {
  if (++i == C) i=0;
	return i;
}

bool por(const vector<int>& w, const vector<int>& a, int j) {
	for (int i : w) {
		if (i != a[j]) return false;
		j = adv(j);
	}
	return true;
}

const int LIMIT = 30;
vector<int> pn, pp;
int nast;

int dziel(int n) {
	if (nast < pn.size() && pn[nast] == n) {
		return pp[nast++];
	}
	int ret = 1, maks_i = 1, _n = n;
	for (int i = 2; i*i <= n; i++) {
		int x = 1;
		while(n % i == 0) {
			maks_i = i;
			n /= i;
			x++;
		}
		ret *= x;
		if (i > 2) i++;
		if (nast < pn.size() && i >= LIMIT) break;
	}
	if (n > 1) ret *= 2;
	if (maks_i >= LIMIT) {
		pn.push_back(_n);
		pp.push_back(ret);
		nast++;
	}
	//printf("dziel %d :: %d\n", _n, ret);
	return ret;
}

int main() {
	int t = GetT();
	long long _n = GetN();
	if (_n > 1e9) return 0;
	int n = _n;
	
	while(t--) {
		nast = 0;
		vector<int> w(C), a(C);
		for (int i = 0; i < C; i++) w[i] = Ask(i);
		for (int i = 1; i < n+C; i++) {
			a[i%C] = dziel(i);
			if (i >= C && por(w, a, (i+1)%C)) {
				Answer(i-C+1);
				break;
			}
		}
		//printf("%d\n", (int)pn.size());
	}
	return 0;
}