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(Q): B=list(map(int, input().split())) qs.append(B) b=B[-1] if b not in D: D[b]=now now+=1 F=[[0]*N for i in range(len(D))] for i in range(N): a=A[i] B=make_divisors(a) for b in B: if b in D: F[D[b]][i]+=1 G=[] for FF in F: C=[0] for f in FF: C.append(C[-1]+f) G.append(C) for l,r,q in qs: if q not in D: print(0) else: qq=D[q] print(G[qq][r]-G[qq][l-1])