#include #include #define rep(i,n) for(int i=0;i vi; typedef vector vl; typedef vector> vvi; typedef vector> vvl; typedef long double ld; typedef pair P; ostream& operator<<(ostream& os, const modint& a) {os << a.val(); return os;} template ostream& operator<<(ostream& os, const static_modint& a) {os << a.val(); return os;} template ostream& operator<<(ostream& os, const dynamic_modint& a) {os << a.val(); return os;} template istream& operator>>(istream& is, vector& v){int n = v.size(); assert(n > 0); rep(i, n) is >> v[i]; return is;} template ostream& operator<<(ostream& os, const pair& p){os << p.first << ' ' << p.second; return os;} template ostream& operator<<(ostream& os, const vector& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : " "); return os;} template ostream& operator<<(ostream& os, const vector>& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : ""); return os;} template void chmin(T& a, T b){a = min(a, b);} template void chmax(T& a, T b){a = max(a, b);} // Sieve of Eratosthenes // https://youtu.be/UTVg7wzMWQc?t=2774 struct Sieve { int n; vector f, primes; Sieve(int n=1):n(n), f(n+1) { f[0] = f[1] = -1; for (ll i = 2; i <= n; ++i) { if (f[i]) continue; primes.push_back(i); f[i] = i; for (ll j = i*i; j <= n; j += i) { if (!f[j]) f[j] = i; } } } vector enum_divisors(long long x){ vector res; for(long long i = 1; i <= n; i++){ if(x % i == 0){ long long square = i * i; if(x > square){ res.push_back(i); res.push_back(x / i); }else if(x == square){ res.push_back(i); }else break; } } return res; } }; const int M = 100000; int main(){ int n, q; cin >> n >> q; vector a(n); cin >> a; Sieve sieve(330); vector> cnt(M + 1); rep(i, n){ auto divisors = sieve.enum_divisors(a[i]); for(int x : divisors){ cnt[x].push_back(i); } } rep(i, q){ int l, r, k; cin >> l >> r >> k; l--; r--; int li = lower_bound(cnt[k].begin(), cnt[k].end(), l) - cnt[k].begin(); int ri = prev(upper_bound(cnt[k].begin(), cnt[k].end(), r)) - cnt[k].begin(); cout << ri - li + 1 << "\n"; } return 0; }