import sys input = sys.stdin.readline from bisect import bisect_left B = 350 M = 101010 N, Q = map(int, input().split()) A = list(map(int, input().split8)) cnt = [[0] * (N + 1) for _ in range(B + 1)] for v in range(B + 1): for i in range(N): cnt[v][i + 1] = cnt[v][i] if A[i] % v == 0: cnt[v][i + 1] += 1 indices = [[] for _ in range(M)] for i in range(N): v = A[i] if v <= B: continue while v < M: indices[v].append(i) v += A[i] for _ in range(Q): L, R, K = map(int, input().split()) L -= 1 if K <= B: print(cnt[K][R] - cnt[K][L]) else: print(bisect_left(indices[K], R) - bisect_left(indices[K], L))