#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; struct Eratosthenes { vector isp,minfactor,myprime,moebius; Eratosthenes (int n) : isp(n+1,1),minfactor(n+1,__INT_MAX__),moebius(n+1,1){ isp[0] = isp[1] = 0; minfactor[0] = 0;minfactor[1] = 1; for(int p = 2;p <= n;p++){ if(!isp[p]) continue; minfactor[p] = p; moebius[p] = -1; myprime.push_back(p); for(int q = 2*p;q <= n;q += p){ isp[q] = false; if(!((q/p)%p)) moebius[q] = 0; else moebius[q] = -moebius[q]; minfactor[q] = min(minfactor[q],p); } } } vector> prime_factorize(int n) { vector> res; while(n-1){ int p = minfactor[n]; int exp = 0; while(minfactor[n] == p){ n /= p; exp ++; } res.push_back(make_pair(p,exp)); } return res; } vector divisors(int n){ vector res; res.push_back(1); auto pf = prime_factorize(n); for(auto [p,e]:pf){ int s = (int)res.size(); for(int i = 0;i < s;i++){ int v = 1; for(int j = 0;j < e;j++){ v *= p; res.push_back(res[i]*v); } } } return res; } }; void Main() { int N,Q; cin >> N >> Q; vector A(N); for(int i = 0;i < N;i++) { cin >> A[i]; } Eratosthenes E((int)1e5); vector L(Q),R(Q),K(Q); vector>> G(N + 1); for(int i = 0;i < Q;i++) { cin >> L[i] >> R[i] >> K[i]; L[i]--; G[L[i]].push_back(make_pair(i, -1)); G[R[i]].push_back(make_pair(i, 1)); } vector ans(Q); vector cnt((int)1e5 + 1); for(int i = 0;i <= N;i++) { for(const auto &[qi, x] : G[i]) { ans[qi] += x * cnt[K[qi]]; } if(i < N) { for(int d : E.divisors(A[i])) { cnt[d]++; } } } for(int i = 0;i < Q;i++) { cout << ans[i] << "\n"; } } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int tt = 1; /* cin >> tt; */ while(tt--) Main(); }