#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 #include #include #include #include #include #define endl codeforces #define ALL(v) std::begin(v), std::end(v) #define ALLR(v) std::rbegin(v), std::rend(v) using ll = std::int64_t; using ull = std::uint64_t; using pii = std::pair; using tii = std::tuple; using pll = std::pair; using tll = std::tuple; template using vec = std::vector; template using vvec = vec>; template const T& var_min(const T &t) { return t; } template const T& var_max(const T &t) { return t; } template const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); } template const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); } template void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); } template void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); } template T make_v(T init) { return init; } template auto make_v(T init, std::size_t s, Tail... tail) { auto v = std::move(make_v(init, tail...)); return vec(s, v); } template struct multi_dem_array { using type = std::array::type, Head>; }; template struct multi_dem_array { using type = std::array; }; template using mdarray = typename multi_dem_array::type; namespace init__ { struct InitIO { InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } } init_io; } ssize_t ceil_pow2(ssize_t s) { ssize_t ret = 1; while (ret < s) ret *= 2; return ret; } namespace segtree { template struct SegmentTree { vec nodes; Op op; T id_ele; auto get_children_idx(ssize_t idx) const -> std::pair { return std::make_pair(2 * idx + 1, 2 * idx + 2); } T get_merged(ssize_t idx) const { ssize_t a, b; std::tie(a, b) = get_children_idx(idx); return op(nodes[a], nodes[b]); } public: SegmentTree(const vec &init_v, Op op, T id_ele) : op(op), id_ele(id_ele) { build(init_v); } void build(const vec &v) { nodes.resize(ceil_pow2(v.size()) * 2 - 1, id_ele); ssize_t sz = size(); std::copy(ALL(v), nodes.begin() + sz - 1); build_parents(); } void build_parents() { ssize_t sz = size(); for (ssize_t i = sz - 2; 0 <= i; i--) nodes[i] = get_merged(i); } ssize_t size() const { return (nodes.size() + 1) / 2; } const T& operator [](ll idx) const { return nodes[idx + size() - 1]; } T get_query(ll ql, ll qr) const { T ret = id_ele; ssize_t lnode = ql + size(), rnode = qr + size(); while (lnode < rnode) { if (lnode & 1) { ret = std::move(op(nodes[lnode - 1], ret)); lnode++; } if (rnode & 1) { rnode--; ret = std::move(op(ret, nodes[rnode - 1])); } lnode /= 2; rnode /= 2; } return ret; } void update_query(ll idx, T val) { idx += size() - 1; nodes[idx] = val; while (idx) { ll pidx = (idx - 1) / 2; nodes[pidx] = get_merged(pidx); idx = pidx; } } template ssize_t lower_bound(F f) const { T sum = id_ele; ssize_t l = 0, r = size(), idx = 0, bidx = 0; if (!f(nodes[0])) return -1; while (true) { if (r - l == 1) { if (!f(sum)) bidx++; break; } auto lidx = 2 * idx + 1; auto ridx = lidx + 1; T nsum = op(sum, nodes[lidx]); ssize_t m = (l + r) / 2; if (f(nsum)) { r = m; idx = lidx; } else { l = m; idx = ridx; bidx = m; sum = std::move(nsum); } } return bidx; } }; } int main() { ll n; std::cin >> n; vec av(n); for (ll &e : av) std::cin >> e; auto op = [](ll a, ll b) { return (a && b ? std::gcd(a, b) : std::max(a, b)); }; segtree::SegmentTree seg(av, op, 0); ll ans = 0; for (ll i = 0; i < n; i++) { if (1 < seg.get_query(i, n)) break; ll ok = n, ng = i; while (1 < std::abs(ok - ng)) { ll mid = (ok + ng) / 2; (seg.get_query(i, mid) == 1 ? ok : ng) = mid; } ans += n - ng; } std::cout << ans << '\n'; return 0; }