#include using namespace std; using ll = long long; template using Pa = pair; template using vec = vector; template using vvec = vector>; template class SegmentTree{ private: int sz; vector seg; const F op; const Monoid e; public: SegmentTree(int n,const F op,const Monoid &e):op(op),e(e){ sz = 1; while(sz<=n) sz <<= 1; seg.assign(2*sz,e); } void set(int k, const Monoid &x){ seg[k+sz] = x; } void build(){ for(int i=sz-1;i>0;i--){ seg[i] = op(seg[2*i],seg[2*i+1]); } } void update(int k,const Monoid &x){ k += sz; seg[k] = x; while(k>>=1){ seg[k] = op(seg[2*k],seg[2*k+1]); } } Monoid query(int l,int r){ Monoid L = e,R = e; for(l+=sz,r+=sz;l>=1,r>>=1){ if(l&1) L = op(L,seg[l++]); if(r&1) R = op(seg[--r],R); } return op(L,R); } Monoid operator[](const int &k)const{ return seg[k+sz]; } template int find_subtree(int a,const C &check,Monoid &M,bool type) { while(a int find_first(int a,const C &check) { Monoid L = e; if(a <= 0) { if(check(op(L,seg[1]))) return find_subtree(1,check,L,false); return -1; } int b = sz; for(a+=sz,b+=sz;a>=1,b>>=1) { if(a&1) { Monoid nxt = op(L,seg[a]); if(check(nxt)) return find_subtree(a,check,L,false); L = nxt; ++a; } } return -1; } template int find_last(int b,const C &check) { Monoid R = e; if(b >= sz) { if(check(op(seg[1], R))) return find_subtree(1, check, R, true); return -1; } int a = sz; for(b+=sz; a>=1,b>>=1) { if(b&1) { Monoid nxt = op(seg[--b],R); if(check(nxt)) return find_subtree(b,check,R,true); R = nxt; } } return -1; } }; int main(){ cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; vec A(N); for(int i=0;i> A[i]; auto op = [&](ll a,ll b){return gcd(a,b);}; SegmentTree seg(N,op,0); for(int i=0;i1) continue; int r = seg.find_first(i,[&](ll b){return gcd(A[i],b)==1;}); ans += N-r; } cout << ans << "\n"; }