#include using namespace std; typedef long long ll; typedef long double ld; typedef pair P; typedef pair Pi; #define rep(i,n) for(ll i=0;i inline bool chmax(T &a, T b){if(a inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;} template ostream& operator<<(ostream& s,const complex& d) {return s<<"("< ostream& operator<<(ostream& s,const pair& d) {return s<<"("< ostream& operator<<(ostream& s, const vector& d){int len=d.size();rep(i,len){s< ostream& operator<<(ostream& s,const vector>& d){int len=d.size();rep(i,len){s< ostream& operator<<(ostream& s,const set& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;} template ostream& operator<<(ostream& s,const map& m){s<<"{"< T gcd(T a,T b) { if (b==0) return a; else return gcd(b,a%b); } template struct SegmentTree{ int sz; vector node; const F op;//演算 const Monoid e;//単位元 SegmentTree(int n,const F op,const Monoid &e):op(op),e(e){ sz=1; while(sz &v){ int n=v.size(); for(int i=0;i=0;i--) node[i]=op(node[2*i+1],node[2*i+2]); } void update(int k,const Monoid &x){ k+=sz-1; node[k]=x; while(k>0){ k=(k-1)/2; node[k]=op(node[2*k+1],node[2*k+2]); } } Monoid query(int a,int b,int k=0,int l=0,int r=-1){ if(r<0) r=sz; if(r<=a || b<=l) return e; if(a<=l && r<=b) return node[k]; else{ Monoid vl=query(a,b,2*k+1,l,(l+r)/2); Monoid vr=query(a,b,2*k+2,(l+r)/2,r); return op(vl,vr); } } Monoid operator[](const int &k)const{ return node[k+sz-1]; } }; int main(){ cin.tie(0);ios::sync_with_stdio(false); ll n; cin>>n; vector a(n); rep(i,n){ cin>>a[i]; } auto op=[](ll a,ll b){return gcd(a,b);}; SegmentTree seg(n,op,0); seg.build(a); ll ans=0,r=0,now=0; rep(l,n){ while(r