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

#pragma GCC maksuje_zadania_na_essie("pot200");
#define loop(i, a, b) for(int i = a; i <= b; i++)
#define loop_rev(i, a, b) for(int i = a; i >= b; i--)
#define all(x) x.begin(), x.end()
#define sz(x) int(x.size())
#define pb push_back

using ll = int64_t;
using ull = uint64_t;
using uint = uint32_t;

constexpr int MAX_N = 1e6 + 1;
vector<int> div_cnt;

vector<int> calc_p(vector<int> const& s) {
  int n = sz(s); vector<int> p(n);
  p[0] = 0;
  loop(i, 1, n-1) {
    p[i] = p[i-1];
    while(p[i] && s[i] != s[p[i]]) {
      p[i] = p[p[i]-1];
    }
    p[i] += (s[i] == s[p[i]]);
  }
  return p;
}

vector<int> calc_matches(vector<int> const& s, vector<int> const& pat) {
  auto pat_p = calc_p(pat);
  int mlen = 0;
  vector<int> matches;
  loop(i, 0, sz(s)-1) {
    while(mlen && s[i] != pat[mlen]) {
      mlen = pat_p[mlen-1];
    }
    mlen += (s[i] == pat[mlen]);
    if(mlen == sz(pat)) {
      matches.pb(i - mlen + 1);
      mlen = pat_p[mlen-1];
    }
  }
  return matches;
}

void sieve(int n) {
  div_cnt.resize(n+1, 0);

  loop(i, 1, n) {
    int j = i;
    while(j <= n) {
      ++div_cnt[j];
      j += i;
    }
  }

}

int main() {
  cin.tie(0)->sync_with_stdio(false);

  int t = GetT();
  int n = GetN();
  int q = GetQ();
  ll c = GetC();

  int gotta_ask = 99;
  sieve(n + gotta_ask);

  while(t--) {
    vector<int> ans(100);
    loop(i, 0, gotta_ask) {
      ans[i] = Ask(i);
    }
    auto res = calc_matches(div_cnt, ans);
    Answer(res[0]);
  }
  
}