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
#include<bits/stdc++.h>
#include"dzilib.h"
using namespace std;
#ifdef DEBUG
auto&operator <<(auto& o, pair<auto, auto> p) {return o<<"("<<p.first<<", "<<p.second<<")";}
auto operator <<(auto& o, auto x)->decltype(x.end(), o) {o<<"{"; for(auto v : x) o<<v<<", "; return o<<"}";}
#define debug(X) cout<<"["#X"]"<<X<<endl;
#else
#define debug(X) {}
#endif
#define int long long
int cnt(int n, vector<int>& sieve)
{
	vector<int> facts;
	while(sieve[n] != 0)
	{
		facts.push_back(sieve[n]);
		n /= sieve[n];
	}
	sort(facts.begin(), facts.end());
	int k = 1;
	int result = 1;
	if(facts.size() == 0) k = 0;
	for(int i=1;i<facts.size();i++)
	{
		if(facts[i] != facts[i-1]) {result *= (k+1); k = 0;}
		k++;
	}
	result *= (k+1);	
	return result;
}
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	const int maxX = 2*(1e6)+100;
	vector<int> sieve(maxX);
	for(int i=2;i<maxX;i++)
	{
		if(sieve[i] == 0)
		{
			sieve[i] = i;
			for(int d = i*i;d<maxX;d+=i)
				sieve[d] = i;
		}
	}
	vector<int> dzk(maxX);
	for(int i=0;i<maxX;i++) dzk[i] = cnt(i, sieve);
	int t = GetT(), q = GetQ();
	q/=t;
	while(t --> 0)
	{
		vector<int> res;
		for(int i=0;i<q;i++)
			res.push_back(Ask(i));
		for(int i=0;i<maxX/2+q;i++)
		{
			int k = 0;
			while(res[k] == dzk[k+i])
			{
				k++;
				if(k == res.size()) break;
			}
			if(k == res.size()) {Answer(i); break;}
		}
	}
}