N,Q=map(int, input().split()) A=list(map(int, input().split())) def make_divisors(n): lower_divisors , upper_divisors = [], [] i = 1 while i*i <= n: if n % i == 0: lower_divisors.append(i) if i != n // i: upper_divisors.append(n//i) i += 1 return lower_divisors + upper_divisors[::-1] D={} qs=[];now=0 for i in range(N): for a in make_divisors(A[i]): if a not in D: D[a]=[] D[a].append(i) import bisect for i in range(Q): B=list(map(int, input().split())) l,r,x=B l-=1;r-=1 if x not in D: print(0) else: d=bisect.bisect_right(D[x],r)-bisect.bisect_left(D[x],l) print(d)