#include #define rep(i,n) for(int i = 0; i < (n); i++) using namespace std; typedef long long ll; template class SWAG { private: class node { public: T val, sum; node(const T &val, const T &sum) : val(val), sum(sum) {} }; Op op; std::stack front_stack, back_stack; public: SWAG(const Op &op = Op()) : op(op), front_stack(), back_stack() {} bool empty() const { return front_stack.empty() && back_stack.empty(); } std::size_t size() const { return front_stack.size() + back_stack.size(); } T fold() const { assert(!empty()); if(front_stack.empty()) return back_stack.top().sum; if( back_stack.empty()) return front_stack.top().sum; return op(front_stack.top().sum, back_stack.top().sum); } void push(const T &x) { if(back_stack.empty()) { back_stack.emplace(x, x); } else { T s = op(back_stack.top().sum, x); back_stack.emplace(x, s); } } void pop() { assert(!empty()); if(front_stack.empty()) { front_stack.emplace(back_stack.top().val, back_stack.top().val); back_stack.pop(); while (!back_stack.empty()) { T s = op(back_stack.top().val, front_stack.top().sum); front_stack.emplace(back_stack.top().val, s); back_stack.pop(); } } front_stack.pop(); } }; int main(){ cin.tie(0); ios::sync_with_stdio(0); int N; cin >> N; vector A(N); rep(i,N) cin >> A[i]; auto op = [](ll x, ll y) { return gcd(x, y); }; SWAG swag(op); ll ans = 0; for(int L = 0, R = 0; L < N; L++) { while(swag.empty() || R < N && swag.fold() != 1LL) swag.push(A[R++]); if(swag.fold() == 1LL) ans += N - R + 1; swag.pop(); } cout << ans << "\n"; }