#include<iostream> #include<unordered_map> #include<vector> #define maxn 1000010 #define ll long long usingnamespacestd;
constint p = 1000000007;
inlineintadd(int x, int y){ return (x += y) >= p ? x - p : x; } inlineintmul(int x, int y){ return1ll * x * y % p; }
int pri[maxn], phi[maxn]; bool isp[maxn]; vector<int> d[maxn]; voidinit_isp(int n){ phi[1] = 1; int cnt = 0; for (int i = 2; i <= n; ++i) { if (!isp[i]) pri[++cnt] = i, phi[i] = i - 1; for (int j = 1; j <= cnt && i * pri[j] <= n; ++j) { isp[i * pri[j]] = 1; if (i % pri[j] == 0) { phi[i * pri[j]] = phi[i] * pri[j]; break; } phi[i * pri[j]] = phi[i] * (pri[j] - 1); } } for (int i = 1; i <= n; ++i) for (int j = i; j <= n; j += i) d[j].push_back(i); }
int n, a[maxn];
int cnt[maxn]; intmain(){ ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
cin >> n; init_isp(n); int ans = 0; for (int i = 1; i <= n; ++i) cin >> a[i]; for (int i = 1; i <= n; ++i) { vector<int> A, use; int sum = 0; for (int j = i; j <= n; j += i) A.push_back(a[j]); for (auto u : A) for (auto v : d[u]) if (++cnt[v] == 1) use.push_back(v); for (auto t : use) sum = add(sum, mul(phi[t], mul(cnt[t], cnt[t]))), cnt[t] = 0; ans = add(ans, mul(sum, phi[i])); } cout << ans << "\n"; return0; }