#include <bits/stdc++.h>
using namespace std;
#define _3bkarm cin.tie(NULL); cout.tie(NULL); ios::sync_with_stdio(false);
struct BIT {
int _n;
vector<long long> _tree;
void init(int get_n) {
_n = get_n, _tree.assign(get_n, 0);
}
void add(int _at, int _value) {
for (int i = _at + 1; i <= _n; i += i & -i)
_tree[i - 1] += _value;
}
long long sum(int _exc) {
long long _ans = 0;
for (int i = _exc; i > 0; i -= i & -i)
_ans += _tree[i - 1];
return _ans;
}
};
void get_shit_done() {
int big = 2'000'01;
int n, q;
cin >> n >> q;
vector<int> a(n);
for (int i = 0; i < n; ++i) cin >> a[i];
vector<vector<pair<int, int>>> L(n), R(n);
for (int iq = 0, l, r, x; iq < q; ++iq) {
cin >> l >> r >> x;
--l, --r;
L[l].push_back({ iq, x });
R[r].push_back({ iq, x });
}
BIT tree;
vector<long long> pref(q), del(q);
long long sum = 0;
tree.init(big);
for (int i = 0; i < n; ++i) {
for (auto [id, x] : L[i]) {
del[id] = del[id] - tree.sum(x + 1);
pref[id] = pref[id] - sum;
}
sum = sum + a[i];
int at = 1;
while (at <= a[i]) {
int t = a[i] / at;
int nxt = a[i] / t + 1;
tree.add(at, t);
tree.add(nxt, -t);
at = nxt;
}
for (auto [id, x] : R[i]) {
del[id] = del[id] + tree.sum(x + 1);
pref[id] = pref[id] + sum;
del[id] = del[id] * x;
}
}
for (int i = 0; i < q; ++i)
cout << pref[i] - del[i] << ' ';
}
signed main() {
_3bkarm
int ts = 1;
// cin >> ts;
while (ts--) {
get_shit_done();
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKI2RlZmluZSBfM2JrYXJtIGNpbi50aWUoTlVMTCk7IGNvdXQudGllKE5VTEwpOyBpb3M6OnN5bmNfd2l0aF9zdGRpbyhmYWxzZSk7CgpzdHJ1Y3QgQklUIHsKICAgIGludCBfbjsKICAgIHZlY3Rvcjxsb25nIGxvbmc+IF90cmVlOwoKICAgIHZvaWQgaW5pdChpbnQgZ2V0X24pIHsKICAgICAgICBfbiA9IGdldF9uLCBfdHJlZS5hc3NpZ24oZ2V0X24sIDApOwogICAgfQoKICAgIHZvaWQgYWRkKGludCBfYXQsIGludCBfdmFsdWUpIHsKICAgICAgICBmb3IgKGludCBpID0gX2F0ICsgMTsgaSA8PSBfbjsgaSArPSBpICYgLWkpCiAgICAgICAgICAgIF90cmVlW2kgLSAxXSArPSBfdmFsdWU7CiAgICB9CgogICAgbG9uZyBsb25nIHN1bShpbnQgX2V4YykgewogICAgICAgIGxvbmcgbG9uZyBfYW5zID0gMDsKICAgICAgICBmb3IgKGludCBpID0gX2V4YzsgaSA+IDA7IGkgLT0gaSAmIC1pKQogICAgICAgICAgICBfYW5zICs9IF90cmVlW2kgLSAxXTsKICAgICAgICByZXR1cm4gX2FuczsKICAgIH0KfTsKCnZvaWQgZ2V0X3NoaXRfZG9uZSgpIHsKICAgIGludCBiaWcgPSAyJzAwMCcwMTsKCiAgICBpbnQgbiwgcTsKICAgIGNpbiA+PiBuID4+IHE7CgogICAgdmVjdG9yPGludD4gYShuKTsKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbjsgKytpKSBjaW4gPj4gYVtpXTsKCiAgICB2ZWN0b3I8dmVjdG9yPHBhaXI8aW50LCBpbnQ+Pj4gTChuKSwgUihuKTsKICAgIGZvciAoaW50IGlxID0gMCwgbCwgciwgeDsgaXEgPCBxOyArK2lxKSB7CiAgICAgICAgY2luID4+IGwgPj4gciA+PiB4OwogICAgICAgIC0tbCwgLS1yOwogICAgICAgIExbbF0ucHVzaF9iYWNrKHsgaXEsIHggfSk7CiAgICAgICAgUltyXS5wdXNoX2JhY2soeyBpcSwgeCB9KTsKICAgIH0KCiAgICBCSVQgdHJlZTsKICAgIHZlY3Rvcjxsb25nIGxvbmc+IHByZWYocSksIGRlbChxKTsKCiAgICBsb25nIGxvbmcgc3VtID0gMDsKICAgIHRyZWUuaW5pdChiaWcpOwogICAgZm9yIChpbnQgaSA9IDA7IGkgPCBuOyArK2kpIHsKICAgICAgICBmb3IgKGF1dG8gW2lkLCB4XSA6IExbaV0pIHsKICAgICAgICAgICAgZGVsW2lkXSA9IGRlbFtpZF0gLSB0cmVlLnN1bSh4ICsgMSk7CiAgICAgICAgICAgIHByZWZbaWRdID0gcHJlZltpZF0gLSBzdW07CiAgICAgICAgfQogICAgICAgIHN1bSA9IHN1bSArIGFbaV07CgogICAgICAgIGludCBhdCA9IDE7CiAgICAgICAgd2hpbGUgKGF0IDw9IGFbaV0pIHsKICAgICAgICAgICAgaW50IHQgPSBhW2ldIC8gYXQ7CiAgICAgICAgICAgIGludCBueHQgPSBhW2ldIC8gdCArIDE7CiAgICAgICAgICAgIHRyZWUuYWRkKGF0LCB0KTsKICAgICAgICAgICAgdHJlZS5hZGQobnh0LCAtdCk7CiAgICAgICAgICAgIGF0ID0gbnh0OwogICAgICAgIH0KCiAgICAgICAgZm9yIChhdXRvIFtpZCwgeF0gOiBSW2ldKSB7CiAgICAgICAgICAgIGRlbFtpZF0gPSBkZWxbaWRdICsgdHJlZS5zdW0oeCArIDEpOwogICAgICAgICAgICBwcmVmW2lkXSA9IHByZWZbaWRdICsgc3VtOwogICAgICAgICAgICBkZWxbaWRdID0gZGVsW2lkXSAqIHg7CiAgICAgICAgfQogICAgfQoKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgcTsgKytpKQogICAgICAgIGNvdXQgPDwgcHJlZltpXSAtIGRlbFtpXSA8PCAnICc7Cn0KCnNpZ25lZCBtYWluKCkgewogICAgXzNia2FybQoKICAgIGludCB0cyA9IDE7Ci8vICAgIGNpbiA+PiB0czsKICAgIHdoaWxlICh0cy0tKSB7CiAgICAgICAgZ2V0X3NoaXRfZG9uZSgpOwogICAgfQoKICAgIHJldHVybiAwOwp9