from bisect import * def divisors(N): res = [] for i in range(1, int(N ** 0.5) + 1): if N % i == 0: res.append(i) if i * i != N: res.append(N // i) return res N, Q = map(int, input().split()) A = list(map(int, input().split())) D = {} for i in range(len(A)): div = divisors(A[i]) for d in div: D.setdefault(d, []) D[d].append(i) for _ in range(Q): L, R, K = map(int, input().split()) L -= 1 R -= 1 if K in D: C = D[K] else: C = [] cnt = bisect_right(C, R) - bisect_left(C, L) print(cnt)