#include using namespace std; int main(){ int N, Q; cin >> N >> Q; vector A(N); map> mp; for (int i = 0; i < N; i++){ cin >> A[i]; for (int j = 1; j * j <= A[i]; j++){ if (A[i] % j == 0){ mp[j].push_back(i); if (j * j != A[i]){ mp[A[i] / j].push_back(i); } } } } for (auto [k, v] : mp){ sort(mp[k].begin(), mp[k].end()); } while (Q--){ int L, R, K; cin >> L >> R >> K; L--; cout << lower_bound(mp[K].begin(), mp[K].end(), R) - lower_bound(mp[K].begin(), mp[K].end(), L) << endl; } }