#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]; } map> mp; for (int i = 0; i < N; 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); } } } } 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) << '\n'; } }