import collections,sys,math,functools,operator,itertools,bisect,heapq,decimal,string,time,random #sys.setrecursionlimit(10**9) #sys.set_int_max_str_digits(0) #input = sys.stdin.readline #n = int(input()) # #alist = [] #s = input() 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] n,q = map(int,input().split()) #for i in range(n): # alist.append(list(map(int,input().split()))) alist = list(map(int,input().split())) c = collections.defaultdict(list) for i in range(n): y = make_divisors(alist[i]) for j in y: c[j].append(i) for i in range(q): l,r,k = map(int,input().split()) l -= 1 r -= 1 le = bisect.bisect_left(c[k],l) ri = bisect.bisect_right(c[k],r) print(ri-le)