// .=*#=
// .=*=+* -#:
// -*+. += .#=
// -*= *- .#=
// :*= *#++#* .%:
// ++. *- =+ -#
// :*- *- *= %-
// .------::. -*. += -+++-. *#
// -*:-=+*#%#*++-. =+ -+ :+*- +@.
// :* .-++-:=++: ++ .# .*: +%-
// .# .:+#- .=*=. =+ *: :++. *+=
// % -%*=-=*. :*+. -* :* :++=. #-+
// #: .=*- .*: :*= .:==++++* +- -**+: :*:+
// += -#: *- :*- :=++=-:. =*- :+++- *-:+
// -# .=*- *- =*+*=: -*= == .# -#++++++++=-:
// @: =*: #: .. -*-# *: == .:-+++:
// ** :#: .#. .*@. =+ +: .-*+:
// :@: .=++=:. -* +. :# #. .+*:
// ## :-*@* +- .#. .# .++=-.
// :@+ =#*++-.# *: -+ .-+++-
// *%- #+- *. .-*+.
// .##- +@ -. .# .++.
// :*++ :% .=+. :*:*: :*-
// =+-*: - :++. .** =. +=
// =+.++: .++. #. == +=
// =+ .=*=. .*: *: *: *:
// -*. :++=: .#. #. .-*- .#
// :*: .=: *: += .-=+++++==++++=: *:
// .*= ... . += -++=:. :+
// -*: .. =++++==++++=: :*+++- #
// .++. == . .== .+%*=. %
// .*+== =#%= %
// :#* .:. -***..::. %
// #: +%@@: -*-+%++=--*- .#
// .*- :=*= -*- =%- *: -=
// =*=. =*- -* # .-. #.
// :=#*++++++++++++++++-:::-+*- #. .*+=#. ==
// *: .*- #----: == %+++++++++: -*
// % -*+- .#: #. +- -*
// % ##:+**. =*%. -% -+ ++
// *: #:+: :**-+= .## :* :*-
// :#=- +-# :*: .#:# :#. :*+.
// .*#+*+. :*. .*: % .#*+=: :*+.
// #..+ :*: #. .++ :+*-
// :**= # :++. == .*+. .:=++=.
// :=++*++=. .# .+%+==++++++-.
// *: .-+++++=-::..
// :* .=++=:.
// +- -*+:
// .#..=*-
// =#*:
// .-
#include <bits/stdc++.h>
#define prob ""
#define int long long
using namespace std;
void file(){
freopen(prob".INP", "r", stdin);
freopen(prob".OUT", "w", stdout);
}
void Init() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
//file();
}
const int maxn = 200002;
struct Query {
int d, id, type;
};
int n, q;
int a[maxn + 7];
long long ans[maxn + 7];
vector<int> b[maxn + 7];
vector<Query> Q[maxn + 7];
int c[maxn + 7], pf[maxn + 7];
void sieve() {
for (int i = 1; i <= maxn; ++i) {
for (int j = i; j <= maxn; j += i) {
b[j].push_back(i);
}
}
}
void Sol() {
sieve();
cin >> n >> q;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
for (int i = 1; i <= q; ++i) {
int l, r, d;
cin >> l >> r >> d;
Q[r].push_back({d, i, 1});
Q[l - 1].push_back({d, i, -1});
}
for (int i = 0; i <= n; ++i) {
if (i > 0) {
for (int x : b[a[i]]) {
c[x]++;
}
pf[a[i]]++;
}
for(auto &ev : Q[i]) {
int t = c[ev.d];
for(int x : b[ev.d]) {
if(x < ev.d) {
t += pf[x];
}
}
ans[ev.id] += ev.type * t;
}
}
for (int i = 1; i <= q; ++i) {
cout << ans[i] << " ";
}
}
signed main(){
Init();
Sol();
return 0;
}