class Divisor(): def __init__(self, N): self.L = list(range(N + 1)) for i in range(2, N + 1): if i != self.L[i]: continue for j in range(2 * i, N + 1, i): self.L[j] = i def factorize(self, n): if n <= 1: return [] D = [] while n != 1: cnt = 0 now = self.L[n] while n % now == 0: cnt += 1 n //= now D.append((now, cnt)) return D def div(self, n): A = self.factorize(n) now = [1] for k, v in A: M = len(now) for i in range(M): x = now[i] for _ in range(v): x *= k now.append(x) return now class Fenwick_Tree: def __init__(self, n): self._n = n self.data = [0] * n def add(self, p, x): assert 0 <= p < self._n p += 1 while p <= self._n: self.data[p - 1] += x p += p & -p def sum(self, l, r): assert 0 <= l <= r <= self._n return self._sum(r) - self._sum(l) def _sum(self, r): s = 0 while r > 0: s += self.data[r - 1] r -= r & -r return s # T.sum(0, x) <= kとなる最大のxを返す。 def get(self, k): k += 1 x, r = 0, 1 while r < self._n: r <<= 1 len = r while len: if x + len - 1 < self._n: if self.data[x + len - 1] < k: k -= self.data[x + len - 1] x += len len >>= 1 return x def __str__(self): temp = [] for i in range(self._n): temp.append(str(self.sum(i, i + 1))) return ' '.join(temp) N, Q = map(int, input().split()) A = list(map(int, input().split())) M = 10 ** 5 + 5 T = Fenwick_Tree(M) query = [[] for _ in range(M)] for i in range(Q): L, R, K = map(int, input().split()) query[K].append((L - 1, R, i)) D = Divisor(M) L = [[] for i in range(M)] for i, a in enumerate(A): for d in D.div(a): L[d].append(i) ans = [-1] * Q for i in range(M): if not query[i]: continue for j in L[i]: T.add(j, 1) for l, r, ind in query[i]: ans[ind] = T.sum(l, r) for j in L[i]: T.add(j, -1) for a in ans: print(a)