#include using namespace std; //*/ #include using namespace atcoder; //*/ #define rep(i,n) for(int i=0;i; using ll = long long; using ull = unsigned long long; //*/ template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } typedef pair pii; typedef pair pll; typedef vector vll; typedef vector vint; random_device rnd; mt19937 rng(rnd()); vector divisor(long long n) { vector ret; for (long long i = 1; i*i <= n; i++) { if (n % i == 0) { ret.push_back(i); if(n/i != i) ret.push_back(n/i); } } sort(ret.begin(),ret.end()); return ret; } int op(int a,int b){return a+b;} int e(){return 0;} void solve(){ int n,q; cin >> n >> q; vint a(n); rep(i,n) cin >> a[i]; set st; rep(i,n){ auto v = divisor(a[i]); for(int x : v) st.insert(x); } map mp; int cnt = 0; for(int x : st) mp[x] = cnt++; vector vs(cnt); rep(i,n){ auto v = divisor(a[i]); for(int x : v) vs[mp[x]].push_back(i); } rep(_,q){ int l,r,k; cin >> l >> r >> k; if(st.find(k) == st.end()){ cout << 0 << '\n'; }else{ int it = vs[mp[k]].end()-lower_bound(ALL(vs[mp[k]]),r); int it2 = vs[mp[k]].end()-lower_bound(ALL(vs[mp[k]]),l-1); cout << it2-it << '\n'; } } } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int t = 1; //cin >> t; rep(testcases,t) solve(); }