#pragma GCC optimize("O3") #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; using P = pair; using T = tuple; template inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;} template inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;} constexpr int MOD = 1e9 + 7; constexpr int inf = 1e9; constexpr long long INF = 1e18; #define all(a) (a).begin(), (a).end() int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; template struct SegmentTree{ private: using Func = function; int n; vector node; Func func; T init_v; public: SegmentTree(vector v, Func _func, T _init_v){ func = _func, init_v = _init_v; int sz = v.size(); n = 1; while(n < sz) n *= 2; node.resize(2 * n, init_v); for(int i=0; i=0; i--) node[i] = func(node[i*2+1], node[i*2+2]); } void update(int idx, T val){ idx += n - 1; node[idx] = val; while(idx > 0){ idx = (idx - 1) / 2; node[idx] = func(node[idx*2+1], node[idx*2+2]); } } T query(int a, int b, int k = 0, int l = 0, int r = -1){ if (r < 0) r = n; if (r <= a || b <= l) return init_v; if (a <= l && r <= b) return node[k]; T lv = query(a, b, k * 2 + 1, l, (l + r) / 2); T rv = query(a, b, k * 2 + 2, (l + r) / 2, r); return func(lv, rv); } }; int main(){ cin.tie(0); ios::sync_with_stdio(false); int n; cin>>n; vector a(n); for(int i=0; i>a[i]; SegmentTree seg(a, [](const auto x, const auto y){return __gcd(x, y);}, 0); ll ans = 0; int r = 0; for(int l=0; l