from bisect import * def make_divisors(n): divisors = [] i = 1 while i ** 2 <= n: if n % i == 0: divisors.append(i) if i ** 2 != n: divisors.append(n // i) i += 1 divisors.sort() return divisors N, Q = map(int, input().split()) A = list(map(int, input().split())) B = [[] for _ in range(10 ** 5 + 1)] for i, a in enumerate(A, start=1): for d in make_divisors(a): B[d].append(i) for _ in range(Q): L, R, K = map(int, input().split()) if K == 1: print(R - L + 1) continue if B[K]: l = bisect_left(B[K], L) r = bisect_right(B[K], R) print(r - l) else: print(0)