def query(l: int, r: int, k: int, a: list[int]) -> int: cnt = 0 for i in range(l-1, r): if a[i] % k == 0: cnt += 1 return cnt def main() -> None: # すべてのkに対して累積和? n, q = map(int, input().split()) a = list(map(int, input().split())) result = [] lrk = [] d: dict = {} for i in range(q): l, r, k = map(int, input().split()) lrk.append((l, r, k)) for i in range(len(lrk)): k = lrk[i][2] l = [0] for j in range(len(a)): if len(l) == 0: l.append(1 if a[j] % k == 0 else 0) else: l.append(l[-1]+(1 if a[j] % k == 0 else 0)) d[k] = l # print(d) for i in range(len(lrk)): l, r, k = lrk[i] result.append(d[k][r]-d[k][l-1]) print(*result, sep="\n") if __name__ == "__main__": main()