#include using namespace std; #define st first #define nd second #define PII pair const int N = 2e5 + 7; const int MX = 1e9 + 7; int n, ans; int in[N]; PII mx[20][N]; vector Left[N], Right[N]; int getPlace(int s, int e){ int p = 0; while((1 << p) <= e - s + 1) ++p; --p; int t = e - (1 << p) + 1; if(mx[p][s].st >= mx[p][t].st) return mx[p][s].nd; return mx[p][t].nd; } void solve(int from, int to){ if(from > to) return; int p = getPlace(from, to); solve(from, p - 1); solve(p + 1, to); for(int i = 1; i < (int)Right[p].size(); ++i){ if(Right[p][i - 1].nd >= to) break; int l1 = min(Right[p][i].nd, to) - Right[p][i - 1].nd; for(int j = 1; j < (int)Left[p].size(); ++j){ if(Left[p][j - 1].nd <= from) break; int l2 = Left[p][j - 1].nd - max(Left[p][j].nd, from); // printf("%d %d %d :: %d %d :: %d %d\n", from, to, p, l1, l2, in[p], __gcd(Right[p][i].st, Left[p][j].st)); ans = (ans + (((1LL * l1 * l2) % MX) * ((1LL * in[p] * __gcd(Right[p][i].st, Left[p][j].st)) % MX)) % MX) % MX; } } } void prepare(){ for(int i = 1; i <= n; ++i) mx[0][i] = {in[i], i}; for(int i = 1; i < 20; ++i) for(int j = 1; j <= n; ++j){ int t = min(j + (1 << (i - 1)), n); if(mx[i - 1][j].st >= mx[i - 1][t].st) mx[i][j] = mx[i - 1][j]; else mx[i][j] = mx[i - 1][t]; } map M; map nxt; for(int i = 1; i <= n; ++i){ nxt.clear(); for(auto v: M){ int d = __gcd(v.st, in[i]); if(!nxt.count(d)) nxt[d] = v.nd; } if(!nxt.count(in[i])) nxt[in[i]] = i; M = nxt; for(auto v: M) Left[i].push_back(v); Left[i].push_back({0, i + 1}); reverse(Left[i].begin(), Left[i].end()); } M.clear(); for(int i = n; i >= 1; --i){ nxt.clear(); for(auto v: M){ int d = __gcd(v.st, in[i]); if(!nxt.count(d)) nxt[d] = v.nd; } if(!nxt.count(in[i])) nxt[in[i]] = i; M = nxt; for(auto v: M) Right[i].push_back(v); Right[i].push_back({0, i - 1}); reverse(Right[i].begin(), Right[i].end()); /* cout << "Left[i]"; for(auto x: Left[i]) cout << x.first << " " << x.second << "\n"; cout << "Right[i]"; for(auto x: Right[i]) cout << x.first << " " << x.second << "\n"; */ } } int main(){ scanf("%d", &n); for(int i = 1; i <= n; ++i) scanf("%d", &in[i]); prepare(); solve(1, n); printf("%d\n", ans); return 0; } /* cteam001:~$ ./begeeks < begeeks1.in 1 2 2 :: 1 1 :: 2 2 1 2 2 :: 1 1 :: 2 1 1 3 3 :: 1 2 :: 3 3 1 3 3 :: 1 1 :: 3 1 1 4 4 :: 1 3 :: 4 4 1 4 4 :: 1 1 :: 4 1 79 cteam001:~$ ./begeeks < begeeks2.in 1 2 2 :: 1 1 :: 4 4 1 2 2 :: 1 1 :: 4 2 1 5 4 :: 1 1 :: 12 12 1 5 4 :: 1 2 :: 12 6 1 5 4 :: 1 1 :: 12 2 1 5 4 :: 1 1 :: 12 3 1 5 4 :: 1 2 :: 12 3 1 5 4 :: 1 1 :: 12 1 456 */