#include // clang-format off using Int = long long; #define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++) #define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__) struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io; #ifndef _MY_DEBUG #define dump(...) #endif // clang-format on /** * author: knshnb * created: Sat Apr 25 15:38:40 JST 2020 **/ template struct SlidingWindowAggregation { const F op; const T e; std::stack> st1, st2; // {val, acc} SlidingWindowAggregation(F op_, T e_) : op(op_), e(e_) { st1.emplace(e, e), st2.emplace(e, e); } int size() { return st1.size() + st2.size() - 2; } void push(T x) { T acc = op(st2.top().second, x); st2.emplace(x, acc); } void pop() { assert(st1.size() > 1 || st2.size() > 1); if (st1.size() > 1) { st1.pop(); } else { while (st2.size() > 2) { T acc = op(st1.top().second, st2.top().first); st1.emplace(st2.top().first, acc); st2.pop(); } st2.pop(); } } T fold_all() { return op(st1.top().second, st2.top().second); } }; template auto make_swag(F op, T e_) { return SlidingWindowAggregation(op, e_); } Int gcd(Int a, Int b) { if (a == 0) return b; if (b == 0) return a; const int s = __builtin_ctzll(a | b); a >>= __builtin_ctzll(a); while (b) { b >>= __builtin_ctzll(b); if (a > b) std::swap(a, b); b -= a; } return a << s; } signed main() { Int n; std::cin >> n; std::vector a(n); REP(i, n) std::cin >> a[i]; a.push_back(1); auto swag = make_swag([](Int x, Int y) { return gcd(x, y); }, 0); Int ans = 0, j = -1; REP(i, n) { while (swag.fold_all() != 1) { swag.push(a[++j]); } ans += n - j; swag.pop(); } std::cout << ans << std::endl; }