n, Q = map(int, input().split()) A = list(map(int, input().split())) add = [[] for _ in range(n)] sub = [[] for _ in range(n)] for i in range(Q): l, r, k = map(int, input().split()) sub[l - 1].append((i, k)) add[r - 1].append((i, k)) ma = max(A) cnt0 = [0] * (ma + 1) cnt1 = [0] * (ma + 1) B = int(ma**0.5) def f(x): if x < B: return cnt0[x] else: tot = 0 for i in range(x, ma + 1, x): tot += cnt1[i] return tot ans = [0] * Q for i, a in enumerate(A): for j, k in sub[i]: ans[j] -= f(k) cnt1[a] += 1 for j in range(1, B): if a % j == 0: cnt0[j] += 1 for j, k in add[i]: ans[j] += f(k) print(*ans, sep="\n")