#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 template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } constexpr long long MAX = 5100000; constexpr long long INF = 1LL << 60; constexpr int inf = 1000000007; constexpr long long mod = 1000000007LL; //constexpr long long mod = 998244353LL; using namespace std; typedef unsigned long long ull; typedef long long ll; template< typename SemiGroup > struct SlidingWindowAggregation { using F = function< SemiGroup(SemiGroup, SemiGroup) >; struct Node { SemiGroup val, sum; Node(const SemiGroup& val, const SemiGroup& sum) : val(val), sum(sum) {} }; SlidingWindowAggregation(F f) : f(f) {} const F f; stack< Node > front, back; bool empty() const { return front.empty() && back.empty(); } size_t size() const { return front.size() + back.size(); } SemiGroup fold_all() const { if (front.empty()) { return back.top().sum; } else if (back.empty()) { return front.top().sum; } else { return f(front.top().sum, back.top().sum); } } void push(const SemiGroup& x) { if (back.empty()) { back.emplace(x, x); } else { back.emplace(x, f(back.top().sum, x)); } } void pop() { if (front.empty()) { front.emplace(back.top().val, back.top().val); back.pop(); while (!back.empty()) { front.emplace(back.top().val, f(back.top().val, front.top().sum)); back.pop(); } } front.pop(); } }; ll f(ll a, ll b) { return gcd(a, b); } int main() { /* cin.tie(nullptr); ios::sync_with_stdio(false); */ ll N; scanf("%lld", &N); vector a(N); for (int i = 0; i < N; i++) scanf("%lld", &a[i]); SlidingWindowAggregation swag(f); ll right = 0; ll res = 0; for (int left = 0; left < N; left++) { if (left != 0) swag.pop(); while (right != N and (swag.empty() or swag.fold_all() != 1)) { swag.push(a[right]); right++; } if (swag.fold_all() == 1) res += N - right + 1; } cout << res << endl; return 0; }