#include <iostream> #include <cassert> #include <vector> #include <map> #include <algorithm> using namespace std; int main() { int N, Q; cin >> N >> Q; map<int, vector<int>> mp; for (int i = 0; i < N; i++) { int a; cin >> a; for (int j = 1; j * j <= a; j++) { if (a % j == 0) { mp[j].push_back(i); if (a / j != j) { mp[a / j].push_back(i); } } } } while (Q--) { int l, r, k; cin >> l >> r >> k; l--; r--; int lidx = lower_bound(mp[k].begin(), mp[k].end(), l) - mp[k].begin(); if (lidx == mp[k].size()) { cout << 0 << endl; continue; } int ridx = lower_bound(mp[k].begin(), mp[k].end(), r) - mp[k].begin(); if (ridx == mp[k].size() || mp[k][ridx] > r) ridx--; cout << ridx - lidx + 1 << endl; } return 0; }