#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,vint(n+1,0)); rep(i,n){ auto v = divisor(a[i]); for(int x : v) vs[mp[x]][i+1] = 1; } rep(i,cnt){ rep(j,n) vs[i][j+1] += vs[i][j]; } rep(_,q){ int l,r,k; cin >> l >> r >> k; if(st.find(k) == st.end()){ cout << 0 << '\n'; }else{ cout << vs[mp[k]][r]-vs[mp[k]][l-1] << '\n'; } } } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int t = 1; //cin >> t; rep(testcases,t) solve(); }