#include using namespace std; using ll = long long; template istream& operator >> (istream& is, vector& vec) { for(T& x : vec) is >> x; return is; } int main(){ ios::sync_with_stdio(false); cin.tie(0); int n, q; cin >> n >> q; const int m = 100000; vector> tb(m + 1); vector> S(m + 1); for(int i = 1; i <= m; i++){ for(int j = i; j <= m; j += i){ tb[j].emplace_back(i); } } for(int i = 0; i < n; i++){ int v; cin >> v; for(auto &&v2 : tb[v]){ S[v2].emplace_back(i); } } while(q--){ int l, r, v; cin >> l >> r >> v; l--; l = lower_bound(S[v].begin(), S[v].end(), l) - tb[v].begin(); r = lower_bound(S[v].begin(), S[v].end(), r) - tb[v].begin(); cout << r - l << '\n'; } }