// https://mojacoder.app/users/heabi/problems/Range-Divisible-Query/submissions/76cb8e16-92b7-4557-9a5c-0adf5bdb8beb #include #include using namespace std; using namespace atcoder; #define rep(i,n)for (int i = 0; i < int(n); ++i) #define rrep(i,n)for (int i = int(n)-1; i >= 0; --i) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() template void chmax(T& a, const T& b) {a = max(a, b);} template void chmin(T& a, const T& b) {a = min(a, b);} using ll = long long; using P = pair; using VI = vector; using VVI = vector; using VL = vector; using VVL = vector; constexpr int B = 710, MX = B * B; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; int q; cin >> q; VI a(n); rep(i, n) cin >> a[i]; VI pos(MX, -1); rep(i, n) pos[a[i]] = i; VVI multiples(B); rep(i, n) for(int d = 1; d < B; d++) if (a[i] % d == 0) multiples[d].push_back(i); while(q--) { int x, l, r; cin >> l >> r>>x; l--; if (x >= B) { int cnt = 0; for(int i = x; i < MX; i += x) { int p = pos[i]; cnt += l <= p && p < r; } cout << cnt << '\n'; } else { auto it_l = lower_bound(all(multiples[x]), l); auto it_r = lower_bound(all(multiples[x]), r); int cnt = it_r - it_l; cout << cnt << '\n'; } } }