#include using namespace std; #define LL long long #define LD long double #define PII pair #define VI vector #define VPII vector #define f first #define s second #define MP make_pair #define PB push_back #define endl '\n' #define SIZ(c) (int)(c).size() #define ALL(c) (c).begin(), (c).end() #define REP(i, n) for (int i = 0; i < (int)(n); i++) #define FOR(i, b, e) for (int i = (b); i <= (int)(e); i++) #define FORD(i, b, e) for (int i = (b); i >= (int)(e); i--) #define ll LL #define st f #define nd s #define mp MP #define pb PB #define eb emplace_back #define siz(c) SIZ(c) const int inf = 1e9 + 7; const LL INF = 1e18L + 7; #define sim template ostream & operator << (ostream &p, pair x) {return p << "<" << x.f << ", " << x.s << ">";} sim> auto operator << (ostream &p, n y) -> typename enable_if::value, decltype(y.begin(), p)>::type {int o = 0; p << "{"; for (auto c : y) {if (o++) p << ", "; p << c;} return p << "}";} void dor() {cerr << "\n";} sim, class...s> void dor(n p, s...y) {cerr << p << " "; dor(y...);} sim, class s> void mini(n &p, s y) {if (p > y) p = y;} sim, class s> void maxi(n &p, s y) {if (p < y) p = y;} #ifdef DEB #define debug(...) dor(__FUNCTION__, ":", __LINE__, ": ", __VA_ARGS__) #else #define debug(...) #endif #define I(x) #x " =", (x), " " const int MXN = 2e5+5; int t[MXN]; const int BASE = 1<<18; PII mx[BASE*2]; PII query(int a, int b) { a += BASE; b += BASE; a--; b++; PII res; while(a / 2 != b / 2) { if(a % 2 == 0)maxi(res, mx[a+1]); if(b % 2 == 1)maxi(res, mx[b-1]); a/=2; b/=2; } return res; } #define left sdffsdjkfhldf #define right sdjkfhldf VPII left[MXN], right[MXN]; // indeks, wartosc LL res; int mod = 1000 * 1000 * 1000 + 7; void add_seg(LL poc1, LL kon1, LL poc2, LL kon2, LL gc, LL mxx, LL a, LL b) { // debug(poc1, kon1, poc2, kon2, gc, mxx); if(poc1 < a)poc1 = a; if(poc1 > kon1)return; if(kon2 > b)kon2 = b; if(kon2 < poc2)return; res += ((LL)kon1-poc1+1) * ((LL)kon2-poc2+1) % mod * gc % mod * mxx % mod; res %= mod; } void calc(int a, int i, int b, int mxx) { int pop_left = i+1; for(auto l: left[i]) { int pop_right = i-1; int gg = l.s; for(auto r: right[i]) { gg = __gcd(gg, r.s); add_seg(l.f, pop_left-1, pop_right+1, r.f, gg, mxx, a, b); pop_right = r.f; if(r.f > b)break; } pop_left = l.f; if(l.f < a)break; } } void go(int a, int b) { if(a > b)return; auto mmm = query(a, b); // debug(a, b, mmm); calc(a, mmm.s, b, mmm.f); go(a, mmm.s-1); go(mmm.s+1, b); } int32_t main() { int n; scanf("%d", &n); FOR(i, 1, n) { scanf("%d", &t[i]); mx[i+BASE] = MP(t[i], i); } FORD(i, BASE-1, 0)mx[i] = max(mx[i*2], mx[i*2+1]); REP(u, 2) { reverse(t+1, t+n+1); map M; FOR(i, 1, n) { for(auto &j: M) j.s = __gcd(j.s, t[i]); M[i] = t[i]; auto it = M.begin(); while(1) { auto it2 = it; it2++; if(it2 == M.end())break; if(it2->s == it->s)M.erase(it2); else it = it2; } left[i].reserve(M.size()); for(auto j: M) left[i].PB(j); } if(u == 0) FOR(i, 1, n) { right[n-i+1] = left[i]; left[i].clear(); for(auto &j: right[n-i+1]) j.f = n-j.f+1; reverse(ALL(right[n-i+1])); } } FOR(i, 1, n) { reverse(ALL(left[i])); // debug(i, t[i], left[i], right[i]); } go(1, n); cout << res << endl; }