#include using namespace std; using ll = long long; const int INF = 1e9 + 10; const ll INFL = 4e18; template struct segment_tree { using F = function; segment_tree() = default; segment_tree(int n, F f, T e) { this->n = n; this->size = n; this->f = f; this->e = e; dat = vector(n << 1, e); } void build(const vector &a) { assert((int)a.size() == n); for (int i = 0; i < (int)a.size(); i++) { dat[i + n] = a[i]; } for (int i = n - 1; i > 0; i--) { dat[i] = f(dat[i << 1], dat[i << 1 | 1]); } } void set(int i, T x) { assert(0 <= i && i < n); i += n; dat[i] = x; while (i) { i >>= 1; dat[i] = f(dat[i << 1], dat[i << 1 | 1]); } } T query(int l, int r) { assert(0 <= l && l <= r && r <= n); l += n; r += n; T ret = e; while (l < r) { if (l & 1) { ret = f(ret, dat[l]); l++; } if (r & 1) { r--; ret = f(ret, dat[r]); } l >>= 1; r >>= 1; } return ret; } T operator[](int i) { assert(0 <= i && i < n); return dat[n + i]; } int size; private: int n; F f; T e; vector dat; }; segment_tree range_max_query(int n) { return segment_tree(n, [](ll a, ll b) { return max(a, b); }, -INFL); } segment_tree range_min_query(int n) { return segment_tree(n, [](ll a, ll b) { return min(a, b); }, INFL); } segment_tree range_sum_query(int n) { return segment_tree(n, [](ll a, ll b) { return a + b; }, 0); } struct dat { dat() {} map mp; }; dat op(dat a, dat b) { dat res; for (auto [k, v] : a.mp) res.mp[k] = v; for (auto [k, v] : b.mp) res.mp[k] += v; return res; } const dat e = dat(); int main() { int N, Q; cin >> N >> Q; vector A(N); for (int i = 0; i < N; i++) { cin >> A[i]; } vector init(N); for (int i = 0; i < N; i++) { for (int j = 1; j * j <= A[i]; j++) { if (A[i] % j == 0) { init[i].mp[j]++; if (j * j != A[i]) init[i].mp[A[i] / j]++; } } } segment_tree seg(N, op, e); seg.build(init); while (Q--) { int l, r, k; cin >> l >> r >> k; l--; dat res = seg.query(l, r); cout << res.mp[k] << '\n'; } }