#pragma GCC optimize("Ofast") #include #include #include using namespace std; using namespace __gnu_pbds; using ll = long long; using ull = unsigned long long; using pii = pair; using pll = pair; #define rep(i, n) for(int i = 0; i < (n); ++i) #define all(x) (x).begin(),(x).end() constexpr char ln = '\n'; constexpr long long MOD = 1000000007LL; //constexpr long long MOD = 998244353LL; template inline bool chmax(T &a, U b) { if (a < b) { a = b; return true;} return false; } template inline bool chmin(T &a, U b) { if (a > b) { a = b; return true;} return false; } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// template struct SlidingWindowAggregation { T unity; Monoid merge; stack> front, back; SlidingWindowAggregation(Monoid f, T id) : merge(f), unity(id) {} bool empty() const {return front.empty() and back.empty();} int size() const {return front.size() + back.size();} T fold_all() const { T vf = front.empty() ? unity : front.top().second; T vb = back.empty() ? unity : back.top().second; return merge(vf,vb); } void emplace(const T &val) { if (back.empty()) { back.emplace(val,val); } else { back.emplace(val,merge(back.top().second,val)); } } void pop() { assert(!empty()); if (front.empty()) { front.emplace(back.top().first,back.top().first); back.pop(); while (!back.empty()) { front.emplace(back.top().first,merge(front.top().second,back.top().first)); back.pop(); } } front.pop(); } }; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; vector A(N); rep(i,N) cin >> A[i]; auto f=[](ll a, ll b) {return __gcd(a,b);}; const ll id = 0; SlidingWindowAggregation SWAG(f,id); int r = 0; ll ans = N*(N+1)/2; rep(l,N) { while (r < N and SWAG.fold_all() != 1) { SWAG.emplace(A[r]); r++; } ans -= SWAG.fold_all() == 1 ? r-l-1 : r-l; SWAG.pop(); } cout << ans << ln; }