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
#include "dzilib.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(ll i=a; i<=b; ++i)
#define FORR(i,a,b) for(ll i=a; i>=b; --i)

constexpr int MAX_Q=5e4+14;
ll qtT, maxQ, maxN, maxC, cQ, nextt[MAX_Q];

ll GetQtDiv(ll cV){
  ll res=1, cQt, cDiv=1;
  while(cV!=1){
    cQt=1, ++cDiv;
    while(cV%cDiv==0) ++cQt, cV/=cDiv;
    res*=cQt;
  }
  return res;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);

  qtT = GetT();
  maxQ = GetQ();
  maxN = GetN();
  maxC = GetC();
  cQ=maxQ/qtT;

  FOR(tt, 1, qtT){
    FOR(nV,0,cQ-1) nextt[nV]=(ll)Ask(nV);
    FOR(cV,1,maxN){
      jump:
      FOR(nV,0,cQ-1) {
        if(GetQtDiv(cV+nV)!=nextt[nV]){
          ++cV;
          goto jump;
        }
      }
      Answer(cV);
      break; 
    }
  }
  return 0;
}