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

const int M = 1001009;
const LL MOD = 1e9 + 7;
int v[M];
int v2[M];

vector<int> p;
int d[M];
LL T, N, Q, C;

void sito(const int n) {
	for (int i = 2; i * i < n; ++i) {
		if (v[i] == false) {
			for (int j = i * 2; j < n; j += i) {
				v[j] = true;
			}
		}
	}
}

int div(int n) {
	if (n == 1)
		return 1;
	int ans = 1;
	for (int i = 0;; i++) {
		if (p[i] * p[i] * p[i] > n)
			break;

		int cnt = 1;
		while (n % p[i] == 0) {
			n = n / p[i];
			cnt = cnt + 1;
		}

		ans = ans * cnt;
	}
	if (v[n] == false) {
		ans = ans * 2;
	} else if (v2[n]) {
		ans = ans * 3;
	} else if (n != 1) {
		ans = ans * 4;
	}
	return ans;
}

const int st = 26;
int ans[st];

int main() {
	sito(M);
	v[0] = true;
	v[1] = true;
	for (int i = 2; i < M; i++) {
		if (v[i] == false) {
			p.push_back(i);
		}
	}
	for (int i = 2; i * i < M; i++) {
		if (v[i] == false) {
			v2[i * i] = true;
		}
	}
	for (int i = 1; i < M; i++) {
		d[i] = div(i);
	}

	T = GetT();

	while (T--) {
		N = GetN();
		Q = GetQ();
		C = GetC();
		for (int i = 0; i < st; i++) {
			ans[i] = Ask(i);
		}
		for (int i = 1; i < M; i++) {
			bool ok = true;
			for (int j = 0; j < st; j++) {
				if (ans[j] != d[i + j]) {
					ok = false;
					break;
				}
			}
			if (ok) {
				Answer(i);
				break;
			}
		}
	}
	return 0;
}