// Author: _Sherbiny
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define endl '\n'
void file() {
#ifndef ONLINE_JUDGE
freopen("in.in", "r", stdin);
freopen("o.in", "w", stdout);
#endif
}
#define Hi ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); file();
/////////////////////////////////////////////////////////////////////////////
template<class T>
struct SparseTable {
// change mxLog
static const int mxLog = 21;
vector<array<T, mxLog>> table;
vector<int> lg;
int n;
SparseTable(int sz) {
n = sz;
table.resize(n + 1);
lg.resize(n + 1);
for (int i = 0; i <= n; ++i) lg[i] = __lg(i);
}
void build(vector<T> &v) {
for (int i = 0; i < v.size(); ++i) table[i][0] = v[i];
for (int j = 1; j < mxLog; ++j)
for (int i = 0; i + (1 << j) - 1 < n; ++i)
table[i][j] = merge(table[i][j - 1], table[i + (1 << (j - 1))][j - 1]);
}
T merge(T &l, T &r) {
return max(l, r);
}
T query(int l, int r) {
int j = lg[r - l + 1];
return merge(table[l][j], table[r - (1 << j) + 1][j]);
}
};
const int N = 5e5 + 10, mod = 1e9 + 7;
SparseTable<pair<int, int>> sp(N);
vector<int> divs[N];
int dp[N];
void go(int l, int r) {
if (l > r) return;
auto [mx, mid] = sp.query(l - 1, r - 1);
if (mid - l < r - mid) {
for (int i = l; i <= mid; ++i) {
for (int &d: divs[i]) {
int cnt = r / d - (mid - 1) / d;
dp[d] += 1ll * cnt * mx % mod;
if (dp[d] >= mod) dp[d] -= mod;
}
}
} else {
for (int i = mid; i <= r; ++i) {
for (int &d: divs[i]) {
int cnt = mid / d - (l - 1) / d;
dp[d] += 1ll * cnt * mx % mod;
if (dp[d] >= mod) dp[d] -= mod;
}
}
}
go(l, mid - 1), go(mid + 1, r);
}
void magic(int tc = 0) {
int n;
cin >> n;
vector<pair<int, int>> v(n);
for (int i = 0; i < n; ++i)
cin >> v[i].first, v[i].second = i + 1;
for (int i = 1; i < N; ++i)
for (int j = i; j < N; j += i)
divs[j].push_back(i);
sp.build(v);
go(1, n);
int res = 0;
for (int i = N - 1; i; --i) {
for (int j = i * 2; j < N; j += i) {
dp[i] -= dp[j];
if (dp[i] < 0) dp[i] += mod;
}
res += 1ll * dp[i] * i % mod * i % mod;
if (res >= mod) res -= mod;
}
cout << res << endl;
}
signed main() {
Hi
int tc = 1;
while (tc--)
magic(tc);
}
Ly8gQXV0aG9yOiBfU2hlcmJpbnkKCiNpbmNsdWRlICJiaXRzL3N0ZGMrKy5oIgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKdHlwZWRlZiBsb25nIGxvbmcgbGw7CiNkZWZpbmUgZW5kbCAnXG4nCgp2b2lkIGZpbGUoKSB7CiNpZm5kZWYgT05MSU5FX0pVREdFCiAgICBmcmVvcGVuKCJpbi5pbiIsICJyIiwgc3RkaW4pOwogICAgZnJlb3Blbigiby5pbiIsICJ3Iiwgc3Rkb3V0KTsKI2VuZGlmCn0KCiNkZWZpbmUgSGkgaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbyhmYWxzZSk7IGNpbi50aWUoMCk7IGNvdXQudGllKDApOyBmaWxlKCk7Ci8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vCgp0ZW1wbGF0ZTxjbGFzcyBUPgpzdHJ1Y3QgU3BhcnNlVGFibGUgewogICAgLy8gY2hhbmdlIG14TG9nCiAgICBzdGF0aWMgY29uc3QgaW50IG14TG9nID0gMjE7CiAgICB2ZWN0b3I8YXJyYXk8VCwgbXhMb2c+PiB0YWJsZTsKICAgIHZlY3RvcjxpbnQ+IGxnOwogICAgaW50IG47CgogICAgU3BhcnNlVGFibGUoaW50IHN6KSB7CiAgICAgICAgbiA9IHN6OwogICAgICAgIHRhYmxlLnJlc2l6ZShuICsgMSk7CiAgICAgICAgbGcucmVzaXplKG4gKyAxKTsKICAgICAgICBmb3IgKGludCBpID0gMDsgaSA8PSBuOyArK2kpIGxnW2ldID0gX19sZyhpKTsKICAgIH0KCiAgICB2b2lkIGJ1aWxkKHZlY3RvcjxUPiAmdikgewogICAgICAgIGZvciAoaW50IGkgPSAwOyBpIDwgdi5zaXplKCk7ICsraSkgdGFibGVbaV1bMF0gPSB2W2ldOwogICAgICAgIGZvciAoaW50IGogPSAxOyBqIDwgbXhMb2c7ICsraikKICAgICAgICAgICAgZm9yIChpbnQgaSA9IDA7IGkgKyAoMSA8PCBqKSAtIDEgPCBuOyArK2kpCiAgICAgICAgICAgICAgICB0YWJsZVtpXVtqXSA9IG1lcmdlKHRhYmxlW2ldW2ogLSAxXSwgdGFibGVbaSArICgxIDw8IChqIC0gMSkpXVtqIC0gMV0pOwogICAgfQoKICAgIFQgbWVyZ2UoVCAmbCwgVCAmcikgewogICAgICAgIHJldHVybiBtYXgobCwgcik7CiAgICB9CgogICAgVCBxdWVyeShpbnQgbCwgaW50IHIpIHsKICAgICAgICBpbnQgaiA9IGxnW3IgLSBsICsgMV07CiAgICAgICAgcmV0dXJuIG1lcmdlKHRhYmxlW2xdW2pdLCB0YWJsZVtyIC0gKDEgPDwgaikgKyAxXVtqXSk7CiAgICB9Cn07Cgpjb25zdCBpbnQgTiA9IDVlNSArIDEwLCBtb2QgPSAxZTkgKyA3OwpTcGFyc2VUYWJsZTxwYWlyPGludCwgaW50Pj4gc3AoTik7CnZlY3RvcjxpbnQ+IGRpdnNbTl07CmludCBkcFtOXTsKCnZvaWQgZ28oaW50IGwsIGludCByKSB7CiAgICBpZiAobCA+IHIpIHJldHVybjsKICAgIGF1dG8gW214LCBtaWRdID0gc3AucXVlcnkobCAtIDEsIHIgLSAxKTsKCiAgICBpZiAobWlkIC0gbCA8IHIgLSBtaWQpIHsKICAgICAgICBmb3IgKGludCBpID0gbDsgaSA8PSBtaWQ7ICsraSkgewogICAgICAgICAgICBmb3IgKGludCAmZDogZGl2c1tpXSkgewogICAgICAgICAgICAgICAgaW50IGNudCA9IHIgLyBkIC0gKG1pZCAtIDEpIC8gZDsKICAgICAgICAgICAgICAgIGRwW2RdICs9IDFsbCAqIGNudCAqIG14ICUgbW9kOwogICAgICAgICAgICAgICAgaWYgKGRwW2RdID49IG1vZCkgZHBbZF0gLT0gbW9kOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfSBlbHNlIHsKICAgICAgICBmb3IgKGludCBpID0gbWlkOyBpIDw9IHI7ICsraSkgewogICAgICAgICAgICBmb3IgKGludCAmZDogZGl2c1tpXSkgewogICAgICAgICAgICAgICAgaW50IGNudCA9IG1pZCAvIGQgLSAobCAtIDEpIC8gZDsKICAgICAgICAgICAgICAgIGRwW2RdICs9IDFsbCAqIGNudCAqIG14ICUgbW9kOwogICAgICAgICAgICAgICAgaWYgKGRwW2RdID49IG1vZCkgZHBbZF0gLT0gbW9kOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfQoKICAgIGdvKGwsIG1pZCAtIDEpLCBnbyhtaWQgKyAxLCByKTsKfQoKdm9pZCBtYWdpYyhpbnQgdGMgPSAwKSB7CiAgICBpbnQgbjsKICAgIGNpbiA+PiBuOwogICAgdmVjdG9yPHBhaXI8aW50LCBpbnQ+PiB2KG4pOwogICAgZm9yIChpbnQgaSA9IDA7IGkgPCBuOyArK2kpCiAgICAgICAgY2luID4+IHZbaV0uZmlyc3QsIHZbaV0uc2Vjb25kID0gaSArIDE7CgogICAgZm9yIChpbnQgaSA9IDE7IGkgPCBOOyArK2kpCiAgICAgICAgZm9yIChpbnQgaiA9IGk7IGogPCBOOyBqICs9IGkpCiAgICAgICAgICAgIGRpdnNbal0ucHVzaF9iYWNrKGkpOwoKICAgIHNwLmJ1aWxkKHYpOwoKICAgIGdvKDEsIG4pOwoKICAgIGludCByZXMgPSAwOwogICAgZm9yIChpbnQgaSA9IE4gLSAxOyBpOyAtLWkpIHsKICAgICAgICBmb3IgKGludCBqID0gaSAqIDI7IGogPCBOOyBqICs9IGkpIHsKICAgICAgICAgICAgZHBbaV0gLT0gZHBbal07CiAgICAgICAgICAgIGlmIChkcFtpXSA8IDApIGRwW2ldICs9IG1vZDsKICAgICAgICB9CgogICAgICAgIHJlcyArPSAxbGwgKiBkcFtpXSAqIGkgJSBtb2QgKiBpICUgbW9kOwogICAgICAgIGlmIChyZXMgPj0gbW9kKSByZXMgLT0gbW9kOwogICAgfQoKICAgIGNvdXQgPDwgcmVzIDw8IGVuZGw7Cn0KCnNpZ25lZCBtYWluKCkgewogICAgSGkKICAgIGludCB0YyA9IDE7CiAgICB3aGlsZSAodGMtLSkKICAgICAgICBtYWdpYyh0Yyk7Cn0=