from collections import defaultdict from bisect import bisect_left, bisect_right def divisors(n: int) -> list: s = set() p = 1 while p * p <= n: if n % p == 0: s.add(p) s.add(n // p) p += 1 return sorted(s) def find_interval(a: list, lo: int, hi: int) -> tuple[int, int, int]: assert lo <= hi empty = 0, -1, -1 # 区間なし if not a or lo > a[-1] or hi < a[0]: return empty l = bisect_left(a, lo) r = bisect_right(a, hi) - 1 if l > r: return empty return r-l+1, l, r N, Q = map(int, input().split()) A = list(map(int, input().split())) d = defaultdict(list) for i, a in enumerate(A): for x in divisors(a): d[x].append(i) for _ in range(Q): L, R, K = map(int, input().split()) L -= 1 R -= 1 t = d[K] cnt, _, _ = find_interval(d[K], L, R) print(cnt)