#include #define st first #define nd second using ll = long long; using namespace std; constexpr int nax = 2e5, logg = 18, rozm = (1 << logg), inf = 1e9 + 1, mod = 1e9 + 7; int n, tab[nax], sum[rozm << 1], val[rozm << 1], res; stack< pair< int, int > > S; vector< pair< int, int > > P; void upd(const int v, const int len) { if (val[v] or v >= rozm) sum[v] = ((ll)len * val[v]) % mod; else { sum[v] = sum[v * 2] + sum[v * 2 + 1]; if (sum[v] >= mod) sum[v] -= mod; } } void laz(const int v, const int len) { if (not val[v]) return; if (v >= rozm) return; val[v * 2] = val[v * 2 + 1] = val[v]; val[v] = 0; upd(v * 2, len / 2); upd(v * 2 + 1, len / 2); } void insert(const int v, const int lp, const int rp, const int lx, const int rx, const int x) { if (rx < lx) return; if (rx < lp or rp < lx) return; if (lx <= lp and rp <= rx) { val[v] = x; upd(v, rp - lp + 1); return; } laz(v, rp - lp + 1); int mi = (lp + rp) / 2; insert(v * 2, lp, mi, lx, rx, x); insert(v * 2 + 1, mi + 1, rp, lx, rx, x); upd(v, rp - lp + 1); } int query(const int v, const int lp, const int rp, const int lx, const int rx) { if (rx < lx) return 0; if (rx < lp or rp < lx) return 0; if (lx <= lp and rp <= rx) return sum[v]; int res = 0; laz(v, rp - lp + 1); int mi = (lp + rp) / 2; res += query(v * 2, lp, mi, lx, rx); res += query(v * 2 + 1, mi + 1, rp, lx, rx); if (res >= mod) res -= mod; return res; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n; for (int i = 0; i < n; ++i) cin >> tab[i]; S.push({inf, n}); for (int i = n - 1; i >= 0; --i) { while (S.top().st <= tab[i]) S.pop(); int hi = S.top().nd; insert(1, 0, rozm - 1, i, hi - 1, tab[i]); S.push({tab[i], i}); P.push_back({tab[i], i}); vector< pair< int, int > > NP; for (auto& p : P) p.st = __gcd(p.st, tab[i]); NP.push_back(P[0]); for (int i = 1; i < P.size(); ++i) if (P[i].st != P[i - 1].st) NP.push_back(P[i]); swap(P, NP); int pop = i; //cerr << "i: " << '\n'; for (int i = (int)P.size() - 1; i >= 0; --i) { int a = query(1, 0, rozm - 1, pop, P[i].nd); //cerr << pop << ' ' << P[i].nd << ' ' << P[i].st << ' ' << a << '\n'; pop = P[i].nd + 1; int b = ((ll)a * P[i].st) % mod; res += b; if (res >= mod) res -= mod; } } cout << res << '\n'; }