#include using namespace std; using ll = long long; const int INF = 1e9 + 10; const ll INFL = 4e18; int main() { int N, Q; cin >> N >> Q; vector A(N); for (int i = 0; i < N; i++) { cin >> A[i]; } const int R = 500; vector> pref(N + 1, vector(R, 0)); for (int i = 0; i < N; i++) { for (int j = 1; j < R; j++) { pref[i + 1][j] = pref[i][j] + (A[i] % j == 0); } } map> mp; for (int i = 0; i < N; i++) { mp[A[i]].push_back(i); } while (Q--) { int l, r, k; cin >> l >> r >> k; l--; if (k < R) { cout << pref[r][k] - pref[l][k] << '\n'; } else { int ans = 0; for (int i = 1; i * k <= R * R; i++) { if (mp.find(i * k) == mp.end()) continue; ans += lower_bound(mp[i * k].begin(), mp[i * k].end(), r) - lower_bound(mp[i * k].begin(), mp[i * k].end(), l); } cout << ans << '\n'; } } }