#include #include #include #include #define rep(i,n) for(ll i = 0; i < n; i++) //[0,n) #define all(A) (A).begin(),(A).end() using namespace std; using ll = long long; template int siz(T& a){return (int)a.size();} vector divisors(int x){ vector res; for(ll i = 1; i*i <= x; i++){ if(x%i != 0) continue; res.push_back(i); if(x/i != i) res.push_back(x/i); } return res; } int main(){ int N,Q; cin >> N >> Q; vector A(N); rep(i,N) cin >> A[i]; map> mp; rep(i,N){ auto D = divisors(A[i]); for(int r : D) mp[r].push_back(i); } rep(i,Q){ int L,R,K; cin >> L >> R >> K; L--; R--; auto cnt = upper_bound(all(mp[K]),R)-lower_bound(all(mp[K]),L); cout << cnt << endl; } }