#include<bits/stdc++.h>
using namespace std;
#define sc(a) scanf("%d", &a)
#define sc2(a,b) scanf("%d%d", &a, &b)
#define sc3(a,b,c) scanf("%d%d%d", &a, &b, &c)
#define pri(x) printf("%d\n", x)
#define mp make_pair
#define pb push_back
#define BUFF ios::sync_with_stdio(false);
#define imprime(v) for(int X=0;X<v.size();X++) printf("%d ", v[X]); printf("\n");
#define endl "\n"
const int INF= 0x3f3f3f3f;
const long double pi= acos(-1);
typedef long long int ll;
typedef long double ld;
typedef pair<int,ll> ii;
typedef vector<int> vi;
typedef vector< vector< int > > vvi;
const int MOD=1e9+7;
const ll LINF=0x3f3f3f3f3f3f3f3f;
ll n;
ll resp;
const int MAXN=200005;
int a[MAXN];
int pen[MAXN],ult[MAXN],pri[MAXN],seg[MAXN];
vi quempri[MAXN];
vi quemseg[MAXN];
ll tr[MAXN*4],lazy[MAXN*4];

void arruma(int i, int j)
{
  if(ult[j]>ult[i])
  {
    if(pen[j]>ult[i])
    {
      pen[i]=pen[j];
    }
    else pen[i]=ult[i];
    ult[i]=ult[j];
  }
  else if(ult[j]>pen[i])
  {
    pen[i]=ult[j];
  }
  if(pri[j]<pri[i])
  {
    if(seg[j]<pri[i])
    {
      seg[i]=seg[j];
    }
    else seg[i]=pri[i];
    pri[i]=pri[j];
  }
  else if(pri[j]<seg[i])
  {
    seg[i]=pri[j];
  }
}

void sieve()
{
  for(int i=1;i<=200000;i++)
  {
    for(int j=i+i;j<=200000;j+=i)
    {
      arruma(i,j);
    }
  }
  for(int i=1;i<=200000;i++)
  {
    if(seg[i]!=INF)
    {
      quempri[pri[i]].pb(i);
      quemseg[seg[i]].pb(i);
    }
  }
}

void push(int nd, int b, int e)
{
  if(lazy[nd]!=0)
  {
    ll tam=e-b+1;
    tr[nd]=tam*lazy[nd];
    if(b!=e)
    {
      lazy[nd*2]=lazy[nd*2+1]=lazy[nd];
    }
    lazy[nd]=0;
  }
}

ll query(int nd, int b, int e, int i, int j)
{
  push(nd,b,e);
  if(i>e or j<b) return 0;
  if(b>=i and e<=j) return tr[nd];
  return query(nd*2,b,(b+e)/2,i,j)+query(nd*2+1,(b+e)/2+1,e,i,j);
}

void update(int nd, int b, int e, int i, int j, ll v)
{
  push(nd,b,e);
  if(i>e or j<b) return;
  if(b>=i and e<=j)
  {
    lazy[nd]=v;
    push(nd,b,e);
    return;
  }
  update(nd*2,b,(b+e)/2,i,j,v);
  update(nd*2+1,(b+e)/2+1,e,i,j,v);
}

ll pegasoma(ll b, ll e)
{
  if(b>e) return 0;
  return query(1,1,n+5,b,e);
}

ll getr(ll b, ll e,ll respant)
{
  if(b==e) return b;
  ll m=(b+e)/2LL;
  if(pegasoma(m,m)>respant) return getr(m+1,e,respant);
  return getr(b,m,respant);
}

void printa_array()
{
  for(int i=1;i<=n;i++)
  {
    cout<<pegasoma(i,i)<<" ";
  }
  cout<<endl;
}

int getl(int b, int e, ll v)
{
  if(b>=e) return b;
  int m=(b+e)/2;
  if(pegasoma(m,m)<v) return getl(b,m,v);
  return getl(m+1,e,v);
}

void atualiza(ll v, int pos)
{
  if(pegasoma(pos,pos)>v) return;
  int l=getl(1,pos,v);
  //cout<<"to colocando "<<v<<" de "<<l<<" a "<<pos<<endl;
  update(1,1,n+5,l,pos,v);
}

void solve()
{
  for(int i=1;i<=200000;i++)
  {

    if(pen[i]!=0)
    {
      atualiza(i,pen[i]-1);
    }
  }
  //cout<<"no inicio , array era :"<<endl;
  //printa_array();
  ll respant=0;
  for(ll l=1;l<=n;l++)
  {
    for(int v : quemseg[l-1])
    {
      respant=max(respant,(ll)v);
    }
    for(int v : quempri[l-1])
    {
   //   cout<<"quempri em "<<l-1<<" = "<<v<<endl;
      atualiza(v,ult[v]-1);
    }
    //cout<<"com l = "<<l<<", o array era :"<<endl;
    //printa_array();
    //cout<<"a respant era "<<respant<<endl;
    ll r=getr(l,n+1,respant);//primeiro r tal que resposta de r seja <= respant
    //cout<<"e achamos o r = "<<r<<endl;
    resp+=pegasoma(l,r-1);
    resp+=(n-r+1LL)*respant;
  }

}

int main()
{
  memset(seg,INF,sizeof(seg));
  memset(pri,INF,sizeof(pri));
  cin>>n;
  for(int i=1;i<=n;i++)
  {
    cin>>a[i];
    pen[a[i]]=ult[a[i]];
    ult[a[i]]=i;
    if(pri[a[i]]==INF)
    {
      pri[a[i]]=i;
    }
    else if(seg[a[i]]==INF)
    {
      seg[a[i]]=i;
    }
  }
  sieve();
  solve();
  //for(int i=1;i<=6;i++) cout<<"val = "<<i<<", pri = "<<pri[i]<<" , seg = "<<seg[i]<<", pen = "<<pen[i]<<", ult = "<<ult[i]<<endl;
  cout<<resp<<endl;
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define sc(a) scanf("%d", &a)
#define sc2(a,b) scanf("%d%d", &a, &b)
#define sc3(a,b,c) scanf("%d%d%d", &a, &b, &c)
#define pri(x) printf("%d\n", x)
#define mp make_pair
#define pb push_back
#define BUFF ios::sync_with_stdio(false);
#define imprime(v) for(int X=0;X<v.size();X++) printf("%d ", v[X]); printf("\n");
#define endl "\n"
const int INF= 0x3f3f3f3f;
const long double pi= acos(-1);
typedef long long int ll;
typedef long double ld;
typedef pair<int,ll> ii;
typedef vector<int> vi;
typedef vector< vector< int > > vvi;
const int MOD=1e9+7;
const ll LINF=0x3f3f3f3f3f3f3f3f;
ll n;
ll resp;
const int MAXN=200005;
int a[MAXN];
int pen[MAXN],ult[MAXN],pri[MAXN],seg[MAXN];
vi quempri[MAXN];
vi quemseg[MAXN];
ll tr[MAXN*4],lazy[MAXN*4];

void arruma(int i, int j)
{
  if(ult[j]>ult[i])
  {
    if(pen[j]>ult[i])
    {
      pen[i]=pen[j];
    }
    else pen[i]=ult[i];
    ult[i]=ult[j];
  }
  else if(ult[j]>pen[i])
  {
    pen[i]=ult[j];
  }
  if(pri[j]<pri[i])
  {
    if(seg[j]<pri[i])
    {
      seg[i]=seg[j];
    }
    else seg[i]=pri[i];
    pri[i]=pri[j];
  }
  else if(pri[j]<seg[i])
  {
    seg[i]=pri[j];
  }
}

void sieve()
{
  for(int i=1;i<=200000;i++)
  {
    for(int j=i+i;j<=200000;j+=i)
    {
      arruma(i,j);
    }
  }
  for(int i=1;i<=200000;i++)
  {
    if(seg[i]!=INF)
    {
      quempri[pri[i]].pb(i);
      quemseg[seg[i]].pb(i);
    }
  }
}

void push(int nd, int b, int e)
{
  if(lazy[nd]!=0)
  {
    ll tam=e-b+1;
    tr[nd]=tam*lazy[nd];
    if(b!=e)
    {
      lazy[nd*2]=lazy[nd*2+1]=lazy[nd];
    }
    lazy[nd]=0;
  }
}

ll query(int nd, int b, int e, int i, int j)
{
  push(nd,b,e);
  if(i>e or j<b) return 0;
  if(b>=i and e<=j) return tr[nd];
  return query(nd*2,b,(b+e)/2,i,j)+query(nd*2+1,(b+e)/2+1,e,i,j);
}

void update(int nd, int b, int e, int i, int j, ll v)
{
  push(nd,b,e);
  if(i>e or j<b) return;
  if(b>=i and e<=j)
  {
    lazy[nd]=v;
    push(nd,b,e);
    return;
  }
  update(nd*2,b,(b+e)/2,i,j,v);
  update(nd*2+1,(b+e)/2+1,e,i,j,v);
}

ll pegasoma(ll b, ll e)
{
  if(b>e) return 0;
  return query(1,1,n+5,b,e);
}

ll getr(ll b, ll e,ll respant)
{
  if(b==e) return b;
  ll m=(b+e)/2LL;
  if(pegasoma(m,m)>respant) return getr(m+1,e,respant);
  return getr(b,m,respant);
}

void printa_array()
{
  for(int i=1;i<=n;i++)
  {
    cout<<pegasoma(i,i)<<" ";
  }
  cout<<endl;
}

int getl(int b, int e, ll v)
{
  if(b>=e) return b;
  int m=(b+e)/2;
  if(pegasoma(m,m)<=v) return getl(m+1,e,v);
  return getl(b,m,v);
}

void atualiza(ll v, int pos)
{
  if(pegasoma(pos,pos)>v) return;
  int l=getl(1,pos,v);
  //cout<<"to colocando "<<v<<" de "<<l<<" a "<<pos<<endl;
  update(1,1,n+5,l,pos,v);
}

void solve()
{
  for(int i=1;i<=200000;i++)
  {

    if(pen[i]!=0)
    {
      atualiza(i,pen[i]-1);
    }
  }
  //cout<<"no inicio , array era :"<<endl;
  //printa_array();
  ll respant=0;
  for(ll l=1;l<=n;l++)
  {
    for(int v : quemseg[l-1])
    {
      respant=max(respant,(ll)v);
    }
    for(int v : quempri[l-1])
    {
   //   cout<<"quempri em "<<l-1<<" = "<<v<<endl;
      atualiza(v,ult[v]-1);
    }
    //cout<<"com l = "<<l<<", o array era :"<<endl;
    //printa_array();
    //cout<<"a respant era "<<respant<<endl;
    ll r=getr(l,n+1,respant);//primeiro r tal que resposta de r seja <= respant
    //cout<<"e achamos o r = "<<r<<endl;
    resp+=pegasoma(l,r-1);
    resp+=(n-r+1LL)*respant;
  }

}

int main()
{
  memset(seg,INF,sizeof(seg));
  memset(pri,INF,sizeof(pri));
  cin>>n;
  for(int i=1;i<=n;i++)
  {
    cin>>a[i];
    pen[a[i]]=ult[a[i]];
    ult[a[i]]=i;
    if(pri[a[i]]==INF)
    {
      pri[a[i]]=i;
    }
    else if(seg[a[i]]==INF)
    {
      seg[a[i]]=i;
    }
  }
  sieve();
  solve();
  /*for(int i=1;i<=6;i++)
  {
    cout<<"val = "<<i<<", pri = "<<pri[i]<<" , seg = "<<seg[i]<<", pen = "<<pen[i]<<", ult = "<<ult[i]<<endl;
  }*/
  cout<<resp<<endl;
  return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;

const int MAXN = 200005;
const int MAXSEG = 1<<19;
int N;
int A[MAXN];
int used[MAXN];
vector<int> D[MAXN];
ll seg[MAXSEG];
ll maxval[MAXSEG];
ll lazy[MAXSEG];
ll cnt[MAXN];

void build_tree(int node, int left, int right)
{
    if (left == right)
    {
        seg[node] = maxval[node] = left;
        return;
    }

    int mid = (left + right)/2;
    build_tree(2*node, left, mid);
    build_tree(2*node+1, mid+1, right);
    seg[node] = seg[2*node] + seg[2*node+1];
    maxval[node] = max(maxval[2*node], maxval[2*node+1]);
}

void down(int node, int left, int right)
{
    if (lazy[node] > 0)
    {
        int mid = (left + right)/2;
        seg[2*node] = (mid - left + 1)*lazy[node];
        seg[2*node+1] = (right - mid)*lazy[node];
        maxval[2*node] = maxval[2*node+1] = lazy[node];
        lazy[2*node] = lazy[2*node+1] = lazy[node];
        lazy[node] = 0;
    }
}

void update(int node, int left, int right, int ql, int qr, ll val)
{
    if (left > right || ql > qr || right < ql || qr < left)
        return;

    if (ql <= left && right <= qr)
    {
        seg[node] = (right - left + 1)*val;
        maxval[node] = val;
        lazy[node] = val;
        return;
    }

    down(node, left, right);

    int mid = (left + right)/2;
    update(2*node, left, mid, ql, qr, val);
    update(2*node+1, mid+1, right, ql, qr, val);
    seg[node] = seg[2*node] + seg[2*node+1];
    maxval[node] = max(maxval[2*node], maxval[2*node+1]);
}

int query(int node, int left, int right, ll val)
{
    if (left == right)
    {
        if (val <= maxval[node])
            return left;
        return N + 1;
    }

    down(node, left, right);

    int mid = (left + right)/2;
    if (val <= maxval[2*node])
        return query(2*node, left, mid, val);
    return query(2*node+1, mid+1, right, val);
}

int main()
{
    ios::sync_with_stdio(0);

    cin >> N;
    for (int i = 1; i <= N; i++)
    {
        cin >> A[i];
        used[A[i]] = i;
    }

    for (int i = 1; i < MAXN; i++)
        for (int j = i; j < MAXN; j += i)
            if (used[j] > 0)
                D[i].push_back(used[j]);

    build_tree(1, 1, N);

    for (int i = MAXN - 1; i >= 1; i--)
    {
        sort(D[i].begin(), D[i].end());
        if (D[i].size() >= 2)
        {
            update(1, 1, N, D[i][1] + 1, N, N + 1);
            int idx = query(1, 1, N, D[i].back());
            update(1, 1, N, D[i][0] + 1, min(idx - 1, D[i][1]), D[i].back());
            idx = query(1, 1, N, D[i][D[i].size() - 2]);
            update(1, 1, N, 1, min(idx - 1, D[i][0]), D[i][D[i].size() - 2]);
        }
        cnt[i - 1] = (ll)N*N - seg[1] + N;
    }

    ll ans = 0;
    for (int i = MAXN - 2; i >= 1; i--)
        ans += (cnt[i] - cnt[i - 1])*i;

    cout << ans << "\n";

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
/***********************************************/
/* Dear online judge:
 * I've read the problem, and tried to solve it.
 * Even if you don't accept my solution, you should respect my effort.
 * I hope my code compiles and gets accepted.
 *  ___  __     _______    _______
 * |\  \|\  \  |\  ___ \  |\  ___ \
 * \ \  \/  /|_\ \   __/| \ \   __/|
 *  \ \   ___  \\ \  \_|/__\ \  \_|/__
 *   \ \  \\ \  \\ \  \_|\ \\ \  \_|\ \
 *    \ \__\\ \__\\ \_______\\ \_______\
 *     \|__| \|__| \|_______| \|_______|
 */
const long long mod = 1000000007;

const int mxN = 200010;

long long val;
long long mxTree[mxN<<2],mnTree[mxN<<2],sumTree[mxN<<2];
bool lz[mxN<<2];
int N;

void push(int n,int l,int r) {
	if(l == r || !lz[n])
		return;
	int md = (l+r)>>1;
	mxTree[n<<1] = mxTree[n<<1|1] = mnTree[n<<1] = mnTree[n<<1|1] = mxTree[n];
	sumTree[n<<1] = mxTree[n<<1] * (md - l + 1ll);
	sumTree[n<<1|1] = mxTree[n<<1|1] * (r - md);
	lz[n] = false;
	lz[n<<1] = lz[n<<1|1] = true;
}

void upd(int a,int b,int n = 1,int l = 0,int r = N) {
	push(n,l,r);
	int md = (l+r)>>1;
	if(mnTree[n] >= val)
		return;
	if(l == a && r == b) {
		if(l == r) {
			mxTree[n] = mnTree[n] = sumTree[n] = val;
		} else if(val > mxTree[n]) {
			mxTree[n] = mnTree[n] = val;
			sumTree[n] = val * (r - l + 1ll);
			lz[n] = true;
		} else {
			if(val > mnTree[n<<1])
				upd(a,min(b,md),n<<1,l,md);
			if(val > mnTree[n<<1|1])
				upd(max(a,md+1),b,n<<1|1,md+1,r);
			mxTree[n] = max(mxTree[n<<1],mxTree[n<<1|1]);
			mnTree[n] = min(mnTree[n<<1],mnTree[n<<1|1]);
			sumTree[n] = sumTree[n<<1] + sumTree[n<<1|1];
		}
		return;
	}
	if(a <= md)
		upd(a,min(b,md),n<<1,l,md);
	if(b > md)
		upd(max(a,md+1),b,n<<1|1,md+1,r);
	mxTree[n] = max(mxTree[n<<1],mxTree[n<<1|1]);
	mnTree[n] = min(mnTree[n<<1],mnTree[n<<1|1]);
	sumTree[n] = sumTree[n<<1] + sumTree[n<<1|1];
}

long long getSum(int a,int b,int n = 1,int l = 0,int r = N) {
	push(n,l,r);
	if(l == a && r == b)
		return sumTree[n];
	int md = (l+r)>>1;
	long long res = 0;
	if(a <= md)
		res += getSum(a,min(b,md),n<<1,l,md);
	if(b > md)
		res += getSum(max(a,md+1),b,n<<1|1,md+1,r);
	return res;
}

int lastOcc[mxN];
int fsOcc[mxN];
vector<long long> dvs[mxN];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);

	srand(time(NULL));

	cin>>N;
	//	N = mxN - 20;
	if(N == 1) {
		cout<<"0\n";
		return 0;
	}
	vector<long long> a(N);
	memset(fsOcc,-1,sizeof fsOcc);
	for(int i = 0;i < N;i++) {
		cin>>a[i];
		//		a[i] = rand();
		for(long long j = 1;j * j <= a[i];j++) {
			if(a[i]%j) continue;
			dvs[i].push_back(j);
			long long other = a[i] / j;
			lastOcc[j] = lastOcc[other] = i;
			if(fsOcc[j] == -1) fsOcc[j] = i;
			if(fsOcc[other] == -1) fsOcc[other] = i;
			if(j != other) dvs[i].push_back(other);
		}
	}

	for(int i = N-1;i >= 1;i--) {
		long long mx = 0;
		for(auto d : dvs[i]) {
			if(lastOcc[d] > i)
				mx = max(mx,d);
		}
		push(1,0,N);
		if(mx > mxTree[1]) {
			val = mx;
			upd(1,i);
		}
	}

	long long res = getSum(1,N-1);
	for(int i = 0;i + 1 < N;i++) {
		long long mx = 0;
		for(auto d : dvs[i]) {
			if(fsOcc[d] < i)
				mx = max(mx,d);
			if(lastOcc[d] > i + 1 && fsOcc[d] == i) {
				val = d;
				upd(i + 2,lastOcc[d]);
			}
		}
		val = mx;
		upd(i + 2,N);
		for(int j = i + 2;j <= N;j++) {
			cerr<<getSum(j,j)<<" \n"[j == N];
		}
		res += getSum(i+2,N);
	}
	cout<<res<<'\n';
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
/***********************************************/
/* Dear online judge:
 * I've read the problem, and tried to solve it.
 * Even if you don't accept my solution, you should respect my effort.
 * I hope my code compiles and gets accepted.
 *  ___  __     _______    _______
 * |\  \|\  \  |\  ___ \  |\  ___ \
 * \ \  \/  /|_\ \   __/| \ \   __/|
 *  \ \   ___  \\ \  \_|/__\ \  \_|/__
 *   \ \  \\ \  \\ \  \_|\ \\ \  \_|\ \
 *    \ \__\\ \__\\ \_______\\ \_______\
 *     \|__| \|__| \|_______| \|_______|
 */
const long long mod = 1000000007;

const int mxN = 200010;

long long val;
long long mxTree[mxN<<2],sumTree[mxN<<2];
bool lz[mxN<<2];
int N;

void push(int n,int l,int r) {
	if(l == r || !lz[n])
		return;
	int md = (l+r)>>1;
	mxTree[n<<1] = mxTree[n<<1|1] = mxTree[n];
	sumTree[n<<1] = mxTree[n<<1] * (md - l + 1ll);
	sumTree[n<<1|1] = mxTree[n<<1|1] * (r - md);
	lz[n] = false;
}

void upd(int a,int b,int n = 1,int l = 0,int r = N) {
	push(n,l,r);
	int md = (l+r)>>1;
	if(val * (r - l + 1ll) <= sumTree[n])
		return;
	if(l == a && r == b) {
		if(l == r) {
			mxTree[n] = sumTree[n] = val;
		} else if(val > mxTree[n]) {
			mxTree[n] = val;
			sumTree[n] = val * (r - l + 1);
			lz[n] = true;
		} else {
			if(val * (md - l + 1) > sumTree[n<<1])
				upd(a,min(b,md),n<<1,l,md);
			if(val * (r - md) > sumTree[n<<1|1])
				upd(max(a,md+1),b,n<<1|1,md+1,r);
		}
		return;
	}
	if(a <= md)
		upd(a,min(b,md),n<<1,l,md);
	if(b > md)
		upd(max(a,md+1),b,n<<1|1,md+1,r);
	mxTree[n] = max(mxTree[n<<1],mxTree[n<<1|1]);
	sumTree[n] = sumTree[n<<1] + sumTree[n<<1|1];
}

long long getSum(int a,int b,int n = 1,int l = 0,int r = N) {
	push(n,l,r);
	if(l == a && r == b)
		return sumTree[n];
	int md = (l+r)>>1;
	long long res = 0;
	if(a <= md)
		res += getSum(a,min(b,md),n<<1,l,md);
	if(b > md)
		res += getSum(max(a,md+1),b,n<<1|1,md+1,r);
	return res;
}

int cntP[mxN];
int lastOcc[mxN];
int fsOcc[mxN];
vector<long long> dvs[mxN];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);

	srand(time(NULL));

	cin>>N;
//	N = mxN - 20;
	if(N == 1) {
		cout<<"0\n";
		return 0;
	}
	vector<long long> a(N);
	memset(fsOcc,-1,sizeof fsOcc);
	for(int i = 0;i < N;i++) {
		cin>>a[i];
//		a[i] = rand();
		for(long long j = 1;j * j <= a[i];j++) {
			if(a[i]%j) continue;
			dvs[i].push_back(j);
			long long other = a[i] / j;
			lastOcc[j] = lastOcc[other] = i;
			if(fsOcc[j] == -1) fsOcc[j] = i;
			if(fsOcc[other] == -1) fsOcc[other] = i;
			if(j != other) dvs[i].push_back(other);
		}
	}

	for(int i = N-1;i >= 1;i--) {
		long long mx = mxTree[1];
		for(auto d : dvs[i]) {
			if(lastOcc[d] > i)
				mx = max(mx,d);
		}
		val = mx;
		upd(1,i);
	}

	long long res = getSum(1,N);
	for(int i = 0;i + 1 < N;i++) {
		long long mx = 0;
		for(auto d : dvs[i]) {
			if(fsOcc[d] < i)
				mx = max(mx,d);
			if(lastOcc[d] > i + 1) {
				val = d;
				upd(i + 2,lastOcc[d]);
			}
		}
		val = mx;
		upd(i + 2,N);
		res += getSum(i+2,N);
	}
	cout<<res<<'\n';
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
/***********************************************/
/* Dear online judge:
 * I've read the problem, and tried to solve it.
 * Even if you don't accept my solution, you should respect my effort.
 * I hope my code compiles and gets accepted.
 *  ___  __     _______    _______
 * |\  \|\  \  |\  ___ \  |\  ___ \
 * \ \  \/  /|_\ \   __/| \ \   __/|
 *  \ \   ___  \\ \  \_|/__\ \  \_|/__
 *   \ \  \\ \  \\ \  \_|\ \\ \  \_|\ \
 *    \ \__\\ \__\\ \_______\\ \_______\
 *     \|__| \|__| \|_______| \|_______|
 */
const long long mod = 1000000007;

const int mxN = 200010;

long long val;
long long mxTree[mxN<<2],mnTree[mxN<<2],sumTree[mxN<<2];
bool lz[mxN<<2];
int N;

void push(int n,int l,int r) {
	if(l == r || !lz[n])
		return;
	int md = (l+r)>>1;
	mxTree[n<<1] = mxTree[n<<1|1] = mnTree[n<<1] = mnTree[n<<1|1] = mxTree[n];
	sumTree[n<<1] = mxTree[n<<1] * (md - l + 1ll);
	sumTree[n<<1|1] = mxTree[n<<1|1] * (r - md);
	lz[n] = false;
	lz[n<<1] = lz[n<<1|1] = true;
}

void upd(int a,int b,int n = 1,int l = 0,int r = N) {
	push(n,l,r);
	int md = (l+r)>>1;
	if(mnTree[n] >= val)
		return;
	if(l == a && r == b) {
		if(l == r) {
			mxTree[n] = mnTree[n] = sumTree[n] = val;
		} else if(val > mxTree[n]) {
			mxTree[n] = mnTree[n] = val;
			sumTree[n] = val * (r - l + 1ll);
			lz[n] = true;
		} else {
			upd(a,min(b,md),n<<1,l,md);
			upd(max(a,md+1),b,n<<1|1,md+1,r);
			mxTree[n] = max(mxTree[n<<1],mxTree[n<<1|1]);
			mnTree[n] = min(mnTree[n<<1],mnTree[n<<1|1]);
			sumTree[n] = sumTree[n<<1] + sumTree[n<<1|1];
		}
		return;
	}
	if(a <= md)
		upd(a,min(b,md),n<<1,l,md);
	if(b > md)
		upd(max(a,md+1),b,n<<1|1,md+1,r);
	mxTree[n] = max(mxTree[n<<1],mxTree[n<<1|1]);
	mnTree[n] = min(mnTree[n<<1],mnTree[n<<1|1]);
	sumTree[n] = sumTree[n<<1] + sumTree[n<<1|1];
}

long long getSum(int a,int b,int n = 1,int l = 0,int r = N) {
	push(n,l,r);
	if(l == a && r == b)
		return sumTree[n];
	int md = (l+r)>>1;
	long long res = 0;
	if(a <= md)
		res += getSum(a,min(b,md),n<<1,l,md);
	if(b > md)
		res += getSum(max(a,md+1),b,n<<1|1,md+1,r);
	return res;
}

int lastOcc[mxN];
int fsOcc[mxN];
vector<long long> dvs[mxN];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);

	srand(time(NULL));

	cin>>N;
	//	N = mxN - 20;
	if(N == 1) {
		cout<<"0\n";
		return 0;
	}
	vector<long long> a(N);
	memset(fsOcc,-1,sizeof fsOcc);
	for(int i = 0;i < N;i++) {
		cin>>a[i];
		//		a[i] = rand();
		for(long long j = 1;j * j <= a[i];j++) {
			if(a[i]%j) continue;
			dvs[i].push_back(j);
			long long other = a[i] / j;
			lastOcc[j] = lastOcc[other] = i;
			if(fsOcc[j] == -1) fsOcc[j] = i;
			if(fsOcc[other] == -1) fsOcc[other] = i;
			if(j != other) dvs[i].push_back(other);
		}
	}

	for(int i = N-1;i >= 1;i--) {
		long long mx = 0;
		for(auto d : dvs[i]) {
			if(lastOcc[d] > i)
				mx = max(mx,d);
		}
		push(1,0,N);
		if(mx > mxTree[1]) {
			val = mx;
			upd(1,i);
		}
	}

	long long res = getSum(1,N-1);
	for(int i = 0;i + 1 < N;i++) {
		long long mx = 0;
		for(auto d : dvs[i]) {
			if(fsOcc[d] < i)
				mx = max(mx,d);
			if(lastOcc[d] > i + 1 && fsOcc[d] == i) {
				val = d;
				upd(i + 2,lastOcc[d]);
			}
		}
		val = mx;
		upd(i + 2,N);
		res += getSum(i+2,N);
	}
	cout<<res<<'\n';
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
/***********************************************/
/* Dear online judge:
 * I've read the problem, and tried to solve it.
 * Even if you don't accept my solution, you should respect my effort.
 * I hope my code compiles and gets accepted.
 *  ___  __     _______    _______
 * |\  \|\  \  |\  ___ \  |\  ___ \
 * \ \  \/  /|_\ \   __/| \ \   __/|
 *  \ \   ___  \\ \  \_|/__\ \  \_|/__
 *   \ \  \\ \  \\ \  \_|\ \\ \  \_|\ \
 *    \ \__\\ \__\\ \_______\\ \_______\
 *     \|__| \|__| \|_______| \|_______|
 */
const long long mod = 1000000007;

const int mxN = 200010;

long long val;
long long mxTree[mxN<<2],sumTree[mxN<<2];
bool lz[mxN<<2];
int N;

void push(int n,int l,int r) {
	if(l == r || !lz[n])
		return;
	int md = (l+r)>>1;
	mxTree[n<<1] = mxTree[n<<1|1] = mxTree[n];
	sumTree[n<<1] = mxTree[n<<1] * (md - l + 1ll);
	sumTree[n<<1|1] = mxTree[n<<1|1] * (r - md);
	lz[n] = false;
}

void upd(int a,int b,int n = 1,int l = 0,int r = N) {
	push(n,l,r);
	int md = (l+r)>>1;
	if(val * (r - l + 1ll) <= sumTree[n])
		return;
	if(l == a && r == b) {
		if(l == r) {
			mxTree[n] = sumTree[n] = val;
		} else if(val > mxTree[n]) {
			mxTree[n] = val;
			sumTree[n] = val * (r - l + 1);
			lz[n] = true;
		} else {
			if(val * (md - l + 1) > sumTree[n<<1])
				upd(a,min(b,md),n<<1,l,md);
			if(val * (r - md) > sumTree[n<<1|1])
				upd(max(a,md+1),b,n<<1|1,md+1,r);
		}
		return;
	}
	if(a <= md)
		upd(a,min(b,md),n<<1,l,md);
	if(b > md)
		upd(max(a,md+1),b,n<<1|1,md+1,r);
	mxTree[n] = max(mxTree[n<<1],mxTree[n<<1|1]);
	sumTree[n] = sumTree[n<<1] + sumTree[n<<1|1];
}

long long getSum(int a,int b,int n = 1,int l = 0,int r = N) {
	push(n,l,r);
	if(l == a && r == b)
		return sumTree[n];
	int md = (l+r)>>1;
	long long res = 0;
	if(a <= md)
		res += getSum(a,min(b,md),n<<1,l,md);
	if(b > md)
		res += getSum(max(a,md+1),b,n<<1|1,md+1,r);
	return res;
}

int lastOcc[mxN];
int fsOcc[mxN];
bool visP[mxN];
vector<long long> dvs[mxN];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);

	srand(time(NULL));

	cin>>N;
//	N = mxN - 20;
	if(N == 1) {
		cout<<"0\n";
		return 0;
	}
	vector<long long> a(N);
	memset(fsOcc,-1,sizeof fsOcc);
	for(int i = 0;i < N;i++) {
		cin>>a[i];
//		a[i] = rand();
		for(long long j = 1;j * j <= a[i];j++) {
			if(a[i]%j) continue;
			dvs[i].push_back(j);
			long long other = a[i] / j;
			lastOcc[j] = lastOcc[other] = i;
			if(fsOcc[j] == -1) fsOcc[j] = i;
			if(fsOcc[other] == -1) fsOcc[other] = i;
			if(j != other) dvs[i].push_back(other);
		}
	}

	for(int i = N-1;i >= 1;i--) {
		long long mx = mxTree[1];
		for(auto d : dvs[i]) {
			if(lastOcc[d] > i)
				mx = max(mx,d);
		}
		val = mx;
		upd(1,i);
	}

	long long res = getSum(1,N);
	for(int i = 0;i + 1 < N;i++) {
		long long mx = 0;
		for(auto d : dvs[i]) {
			if(fsOcc[d] < i)
				mx = max(mx,d);
			if(lastOcc[d] > i + 1 && !visP[d]) {
				val = d;
				visP[d] = true;
				upd(i + 2,lastOcc[d]);
			}
		}
		val = mx;
		upd(i + 2,N);
		res += getSum(i+2,N-1) + mx;
	}
	cout<<res<<'\n';
	return 0;
}


#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

int N;
int A[200111];
VI G[200111];

int main() {
    scanf("%d", &N);
    REP (i, N) scanf("%d", A+i);

    REP (i, N) {
	int m = A[i];
	for (int k=1; k*k<=m; k++) {
	    if (m % k == 0) {
		G[k].push_back(i);
		if (k*k < m) G[m/k].push_back(i);
	    }
	}
    }

    LL ans = 0;
    vector<pair<int, int> > cur(N+1);
    REP (i, N+1) cur[i] = make_pair(i, i);

    for (int a=200000; a>0; a--) if (G[a].size() > 1u) {
	sort(G[a].begin(), G[a].end());
	vector<pair<int, int> > X, nxt;
	if (0 < G[a].end()[-2]) X.emplace_back(0, G[a].end()[-2]);
	if (G[a][0] < G[a].back()-1) X.emplace_back(G[a][0]+1, G[a].back());
	if (G[a][1] < N-1) X.emplace_back(G[a][1]+1, N);

	EACH (e, X) {
	    bool zero = false;
	    REP (i, cur.size()) if (e->first >= cur[i].first && e->second <= cur[i].second) {
		zero = true;
		break;
	    }

	    if (zero) continue;

	    int last = 0;
	    REP (i, cur.size()) {
		if (e->second <= last) break;

		if (cur[i].first > e->first) {
		    if (cur[i].second < e->second) {
			ans += (LL)a * (cur[i].second - last) * (cur[i].first - e->first);
		    } else {
			ans += (LL)a * (e->second - last) * (cur[i].first - e->first);
		    }
		}

		last = cur[i].second;
	    }

	    nxt.clear();
	    bool inserted = false;
	    REP (i, cur.size()) {
		if (cur[i].first < e->first) nxt.push_back(cur[i]);
		else {
		    if (!inserted) {
			nxt.push_back(*e);
			inserted = true;
		    }
		    if (cur[i].second > e->second) nxt.push_back(cur[i]);
		}
	    }
	    swap(cur, nxt);
	}

//	EACH (e, cur) eprintf("(%d %d) ", e->first, e->second); eprintf("\n");
    }

    printf("%lld\n", ans);

    return 0;
}


//let's do it
 #include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define inf 1000000000000
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define S second
#define F first
#define boost1 ios::sync_with_stdio(false);
#define boost2 cin.tie(0);
#define mem(a,val) memset(a,val,sizeof a)
#define endl "\n"
#define maxn 200005

struct st
{
	ll sum;
	ll mini,maxi;
	st()
	{
		sum=mini=maxi=0;
	}
}tree[4*maxn];
ll a[maxn],lazy[4*maxn];
ll f[maxn];
vector<ll>divisors[maxn],store[maxn];

void lazy_update(ll node,ll a,ll b)
{
	if(lazy[node]==-1)
	return;
	tree[node].sum=(b-a+1)*lazy[node];
	tree[node].mini=tree[node].maxi=lazy[node];
	if(a!=b)
	{
		lazy[2*node]=lazy[node];
		lazy[2*node+1]=lazy[node];
	}
	lazy[node]=-1;
	return;
}
void build(ll node,ll a,ll b)
{
	if(a==b)
	{
		tree[node].sum=a;
		tree[node].mini=a;
		tree[node].maxi=a;
		return;
	}
	ll mid=(a+b)/2;
	build(2*node,a,mid);
	build(2*node+1,mid+1,b);
	tree[node].sum=tree[2*node].sum+tree[2*node+1].sum;
	tree[node].mini=min(tree[2*node].mini,tree[2*node+1].mini);
	tree[node].maxi=max(tree[2*node].maxi,tree[2*node+1].maxi);
}
void update(ll node,ll a,ll b,ll l,ll r,ll val)
{
	lazy_update(node,a,b);
	if(a>b || a>r || b<l || tree[node].mini>=val)
	return;
	if(a>=l && b<=r && a==b)
	{
		tree[node].sum=max(tree[node].sum,val);
		tree[node].maxi=tree[node].mini=tree[node].sum;
		return;
	}
	if(a>=l && b<=r && tree[node].maxi<=val)
	{
		lazy[node]=val;
		lazy_update(node,a,b);
		return;
	}
	ll mid=(a+b)/2;
	update(2*node,a,mid,l,r,val);
	update(2*node+1,mid+1,b,l,r,val);
	tree[node].sum=tree[2*node].sum+tree[2*node+1].sum;
	tree[node].mini=min(tree[2*node].mini,tree[2*node+1].mini);
	tree[node].maxi=max(tree[2*node].maxi,tree[2*node+1].maxi);
}
int main()
{
	boost1;boost2;
	ll i,j,n,x,y,first_pos,second_pos,last,second_last;
	ll ans=0;
	for(i=0;i<maxn;i++)
	lazy[i]=-1;
	for(i=1;i<maxn;i++)
	{
		for(j=i;j<maxn;j+=i)
		divisors[j].pb(i);
	}
	cin>>n;
	for(i=1;i<=n;i++)
	{
		cin>>a[i];
		for(auto it:divisors[a[i]])
		store[it].pb(i);
	}
	build(1,1,n);
	f[maxn-1]=n*n+n-tree[1].sum;
	for(i=maxn-1;i>=1;i--)
	{
		if(store[i].size()>=2)
		{
			first_pos=store[i][0];
			second_pos=store[i][1];
			last=store[i][store[i].size()-1];
			second_last=store[i][store[i].size()-2];
			update(1,1,n,second_pos+1,n,n+1);
			update(1,1,n,first_pos+1,second_pos,last);
			update(1,1,n,1,first_pos,second_last);
		}
		f[i-1]=n*n+n-tree[1].sum;
	}
	for(i=1;i<maxn;i++)
	ans+=i*(f[i]-f[i-1]);
	cout<<ans;
	return 0;
}
/*
3
2 6 3
*/


//let's do it
 #include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define inf 1000000000000
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define S second
#define F first
#define boost1 ios::sync_with_stdio(false);
#define boost2 cin.tie(0);
#define mem(a,val) memset(a,val,sizeof a)
#define endl "\n"
#define maxn 200005

struct st
{
	ll sum;
	int mini,maxi;
	st()
	{
		sum=mini=maxi=0;
	}
}tree[4*maxn];
int a[maxn],lazy[4*maxn];
ll f[maxn];
vector<int>divisors[maxn],store[maxn];

void lazy_update(int node,int a,int b)
{
	if(lazy[node]==-1)
	return;
	tree[node].sum=(b-a+1)*lazy[node];
	tree[node].mini=tree[node].maxi=lazy[node];
	if(a!=b)
	{
		lazy[2*node]=lazy[node];
		lazy[2*node+1]=lazy[node];
	}
	lazy[node]=-1;
	return;
}
void build(int node,int a,int b)
{
	if(a==b)
	{
		tree[node].sum=a;
		tree[node].mini=a;
		tree[node].maxi=a;
		return;
	}
	int mid=(a+b)/2;
	build(2*node,a,mid);
	build(2*node+1,mid+1,b);
	tree[node].sum=tree[2*node].sum+tree[2*node+1].sum;
	tree[node].mini=min(tree[2*node].mini,tree[2*node+1].mini);
	tree[node].maxi=max(tree[2*node].maxi,tree[2*node+1].maxi);
}
void update(int node,int a,int b,int l,int r,ll val)
{
	lazy_update(node,a,b);
	if(a>b || a>r || b<l || tree[node].mini>=val)
	return;
	if(a>=l && b<=r && a==b)
	{
		tree[node].sum=max(tree[node].sum,val);
		tree[node].maxi=tree[node].mini=tree[node].sum;
		return;
	}
	if(a>=l && b<=r && tree[node].maxi<=val)
	{
		lazy[node]=val;
		lazy_update(node,a,b);
		return;
	}
	int mid=(a+b)/2;
	update(2*node,a,mid,l,r,val);
	update(2*node+1,mid+1,b,l,r,val);
	tree[node].sum=tree[2*node].sum+tree[2*node+1].sum;
	tree[node].mini=min(tree[2*node].mini,tree[2*node+1].mini);
	tree[node].maxi=max(tree[2*node].maxi,tree[2*node+1].maxi);
}
int main()
{
	boost1;boost2;
	int i,j,n,x,y,first_pos,second_pos,last,second_last;
	ll ans=0;
	for(i=0;i<maxn;i++)
	lazy[i]=-1;
	for(i=1;i<maxn;i++)
	{
		for(j=i;j<maxn;j+=i)
		divisors[j].pb(i);
	}
	cin>>n;
	for(i=1;i<=n;i++)
	{
		cin>>a[i];
		for(auto it:divisors[a[i]])
		store[it].pb(i);
	}
	build(1,1,n);
	f[maxn-1]=n*n+n-tree[1].sum;
	for(i=maxn-1;i>=1;i--)
	{
		if(store[i].size()>=2)
		{
			first_pos=store[i][0];
			second_pos=store[i][1];
			last=store[i][store[i].size()-1];
			second_last=store[i][store[i].size()-2];
			update(1,1,n,second_pos+1,n,n+1);
			update(1,1,n,first_pos+1,second_pos,last);
			update(1,1,n,1,first_pos,second_last);
		}
		f[i-1]=n*n+n-tree[1].sum;
	}
	for(i=1;i<maxn;i++)
	ans+=i*(f[i]-f[i-1]);
	cout<<ans;
	return 0;
}
/*
3
2 6 3
*/


//let's do it
 #include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define inf 1000000000000
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define S second
#define F first
#define boost1 ios::sync_with_stdio(false);
#define boost2 cin.tie(0);
#define mem(a,val) memset(a,val,sizeof a)
#define endl "\n"
#define maxn 200005

struct st
{
	ll sum;
	int mini,maxi;
	st()
	{
		sum=mini=maxi=0;
	}
}tree[4*maxn];
int a[maxn],lazy[4*maxn];
ll f[maxn];
vector<int>divisors[maxn],store[maxn];

void lazy_update(int node,int a,int b)
{
	if(lazy[node]==-1)
	return;
	tree[node].sum=(b-a+1)*lazy[node];
	tree[node].mini=tree[node].maxi=lazy[node];
	if(a!=b)
	{
		lazy[2*node]=lazy[node];
		lazy[2*node+1]=lazy[node];
	}
	lazy[node]=-1;
	return;
}
void build(int node,int a,int b)
{
	if(a==b)
	{
		tree[node].sum=a;
		tree[node].mini=a;
		tree[node].maxi=a;
		return;
	}
	int mid=(a+b)/2;
	build(2*node,a,mid);
	build(2*node+1,mid+1,b);
	tree[node].sum=tree[2*node].sum+tree[2*node+1].sum;
	tree[node].mini=min(tree[2*node].mini,tree[2*node+1].mini);
	tree[node].maxi=min(tree[2*node].maxi,tree[2*node+1].maxi);
}
void update(int node,int a,int b,int l,int r,ll val)
{
	lazy_update(node,a,b);
	if(a>b || a>r || b<l || tree[node].mini>=val)
	return;
	if(a>=l && b<=r && a==b)
	{
		tree[node].sum=max(tree[node].sum,val);
		tree[node].maxi=tree[node].mini=tree[node].sum;
		return;
	}
	if(a>=l && b<=r && tree[node].maxi<=val)
	{
		lazy[node]=val;
		lazy_update(node,a,b);
		return;
	}
	int mid=(a+b)/2;
	update(2*node,a,mid,l,r,val);
	update(2*node+1,mid+1,b,l,r,val);
	tree[node].sum=tree[2*node].sum+tree[2*node+1].sum;
	tree[node].mini=min(tree[2*node].mini,tree[2*node+1].mini);
	tree[node].maxi=min(tree[2*node].maxi,tree[2*node+1].maxi);
}
int main()
{
	boost1;boost2;
	int i,j,n,x,y,first_pos,second_pos,last,second_last;
	ll ans=0;
	for(i=0;i<maxn;i++)
	lazy[i]=-1;
	for(i=1;i<maxn;i++)
	{
		for(j=i;j<maxn;j+=i)
		divisors[j].pb(i);
	}
	cin>>n;
	for(i=1;i<=n;i++)
	{
		cin>>a[i];
		for(auto it:divisors[a[i]])
		store[it].pb(i);
	}
	build(1,1,n);
	f[maxn-1]=n*n+n-tree[1].sum;
	for(i=maxn-1;i>=1;i--)
	{
		if(store[i].size()>=2)
		{
			first_pos=store[i][0];
			second_pos=store[i][1];
			last=store[i][store[i].size()-1];
			second_last=store[i][store[i].size()-2];
			update(1,1,n,second_pos+1,n,n+1);
			update(1,1,n,first_pos+1,second_pos,last);
			update(1,1,n,1,first_pos,second_last);
		}
		f[i-1]=n*n+n-tree[1].sum;
	}
	for(i=1;i<maxn;i++)
	ans+=i*(f[i]-f[i-1]);
	cout<<ans;
	return 0;
}
/*
3
2 6 3
*/


#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
#define Int register int
const int MAXN = 200005;
int n, g, a[MAXN], next[MAXN];
long long ans;
vector<int> s[MAXN];

inline void solve(Int L, Int R) {
	for(Int i = L; i <= min(n,R); ++i)
		if(next[i] < R) ans += 1LL * g * (R - next[i]), next[i] = R;
		else break;
}

int main() {
	scanf("%d", &n);
	for(Int i = 1; i <= n; ++i) {
		scanf("%d", a + i);
		next[i] = i;
		for(Int j = 1; j * j <= a[i]; ++j) if(a[i] % j == 0) {
			s[a[i] / j].push_back(i);
			if(j * j != a[i]) s[j].push_back(i);
		}
	}

	for(g = 200000; g; --g) {
		if(s[g].size() < 2) continue;
		solve(s[g][1] + 1, n+1);
		solve(s[g][0] + 1, s[g][s[g].size() - 1]);
		solve(1, s[g][s[g].size() - 2]);
	}
	printf("%lld\n", ans);
	return 0;
}


#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
#define Int register int
const int MAXN = 200005;
int n, g, a[MAXN], Next[MAXN];
long long ans;
vector<int> s[MAXN];

inline void solve(Int L, Int R) {
	for(Int i = L; i <= min(n,R); ++i)
		if(Next[i] < R) ans += 1LL * g * (R - Next[i]), Next[i] = R;
		else break;
}

int main() {
	scanf("%d", &n);
	for(Int i = 1; i <= n; ++i) {
		scanf("%d", a + i);
		Next[i] = i;
		for(Int j = 1; j * j <= a[i]; ++j) if(a[i] % j == 0) {
			s[a[i] / j].push_back(i);
			if(j * j != a[i]) s[j].push_back(i);
		}
	}

	for(g = 200000; g; --g) {
		if(s[g].size() < 2) continue;
		solve(s[g][1] + 1, n+1);
		solve(s[g][0] + 1, s[g][s[g].size() - 1]);
		solve(1, s[g][s[g].size() - 2]);
	}
	printf("%lld\n", ans);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define PB push_back
#define ZERO (1e-10)
#define INF (1<<29)
#define CL(A,I) (memset(A,I,sizeof(A)))
#define DEB printf("DEB!\n");
#define D(X) cout<<"  "<<#X": "<<X<<endl;
#define EQ(A,B) (A+ZERO>B&&A-ZERO<B)
typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
#define IN(n) int n;scanf("%d",&n);
#define FOR(i, m, n) for (int i(m); i < n; i++)
#define F(n) FOR(i,0,n)
#define FF(n) FOR(j,0,n)
#define FT(m, n) FOR(k, m, n)
#define aa first
#define bb second
void ga(int N,int *A){F(N)scanf("%d",A+i);}
#define MX (200009)
int P[MX],L,D[MX]={0,1};
void gen(){
    FT(2,MX){
        if(!D[k])D[k]=k,P[L++]=k;
        FF(L&&P[j]<=D[k]&&k*P[j]<MX)D[k*P[j]]=P[j];
    }
}
int fc(int N,int*f,int*c){
	if(N==1)return 0;
    static int H[64];
    int J=0,I=0;
    while(D[N]^N)H[J++]=D[N],N/=D[N];
    H[J++]=N;
    sort(H,H+J);
    F(J)if(!i||H[i]^f[I-1])f[I]=H[i],c[I++]=1;
        else ++c[I-1];
    return I;
}
void rec(int*f,int*c,int p,int L,vi&o,int S){
    if(p==L)o.PB(S);
    else F(c[p]+1)rec(f,c,p+1,L,o,S),S*=f[p];
}
void dsr(int N,vi&o){
    o.clear();
    static int f[64],c[64];
    int L(fc(N,f,c));
    rec(f,c,0,L,o,1);
//    sort(o.begin(),o.end());
}
vi o,V[MX];
map<int,int> H;
ll A[MX],S,T;
int N,a;
void qr(int B,int E){
    if(B>E)return;
    auto h=H.upper_bound(B);
    --h;
	if(h->bb>=E)return;
	int X=B,Y=h->bb;
	H[B]=E;
	while(!H.empty()){
		h=H.upper_bound(B);
		T-=Y*1ll*(h->aa-X);
		X=h->aa,Y=h->bb;
		if(Y>E){T+=(X-B)*1ll*E;return;}
		H.erase(h);
	}
}
int main(void){
    gen(),scanf("%d",&N),T=N*(N-1ll)/2,H[N+1]=INF,H[0]=0;
    F(N){
        H[i+1]=i,scanf("%d",&a),dsr(a,o);
        for(auto&h:o)V[h].PB(i+1);
    }
    for(int i=MX-1;i;--i){
        if(V[i].size()>1u)a=V[i].size(),qr(1,V[i][a-2]-1),qr(V[i][0]+1,V[i][a-1]-1),qr(V[i][1]+1,N);
        S+=T-N*(N-1ll)/2;
    }
    printf("%lld\n",S);
    return 0;
}


#include <cstdio>
#include <cassert>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

typedef pair<int, int> pii;

#define NR 501000
const int W = 200000;

typedef long long i64;

const int inf = 1e9;

map<int, int> q;
vector<int> fac[NR], appear[NR];
vector<pii> vec[NR];
int a[NR];
i64 sum, ans;
int n;

#define w0 first
#define w1 second

void update(int p, int w) {
	//printf("!!!upd %d %d\n", p, w);
	auto it = q.upper_bound(p);
	if (it != q.end() && it->w1 >= w) return;
	int last = p, last_w = it == q.end() ? 0 : it->w1;
	//fprintf(stderr, "!%d %d %d\n", p, q.begin()->w0, it!=q.begin());
	assert(it != q.begin());
	--it;
	if (q[p] >= w) return;
	for (; ; ) {
		//printf("[%d %d] %d->%d\n", it->w0 + 1, last, last_w, w);
		sum += 1ll * (last - it->w0) * (w - last_w);
		last_w = it->w1;
		last = it->w0;

		if (it->w1 > w) {
			q[p] = w;
			break;
		} else {
			assert(it != q.begin());
			auto tmp = it;
			--it;
			q.erase(tmp);
		}
	}
	//printf("S: %lld\n", sum);
}

int access(int p) {
	auto it = q.lower_bound(p);
	return it == q.end() ? 0 : it->w1;
}

int main() {
	scanf("%d", &n);

	for (int i = 1; i <= W; ++i)
		for (int j = i; j <= W; j += i)
			fac[j].push_back(i);

	for (int i = 1; i <= n; ++i) {
		scanf("%d", &a[i]);
		for (int p : fac[a[i]]) appear[p].push_back(i);
	}

	q[0] = inf;

	for (int i = 1; i <= n; ++i) {
		for (int p : fac[a[i]]) {
			int size = appear[p].size();
			if (size == 1) continue;
			int fi = appear[p][size - 1],
				se = appear[p][size - 2],
				h  = appear[p][0];

			if (se - 1 > 0) update(se - 1, p);
			if (fi - 1 > 0) vec[h + 1].push_back(pii(fi - 1, p));//, printf("!!!!%d %d\n", fi - 1, p);
			vec[appear[p][1] + 1].push_back(pii(n, p));
		}
	}

	for (int i = 1; i <= n; ++i) {
		for (pii t : vec[i]) update(t.w0, t.w1);
			//printf("$%d %lld\n", i, sum);

		ans += sum;
		if (i == 1) ans -= access(n - 1);
		sum -= access(i);
		q[i] = inf;
	}

	printf("%lld\n", ans);
	return 0;
}


#include <cstdio>
#include <cassert>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

typedef pair<int, int> pii;

#define NR 501000
const int W = 200000;

typedef long long i64;

const int inf = 1e9;

map<int, int> q;
vector<int> fac[NR], appear[NR];
vector<pii> vec[NR];
int a[NR];
i64 sum, ans;
int n;

#define w0 first
#define w1 second

void update(int p, int w) {
	//printf("!!!upd %d %d\n", p, w);
	auto it = q.upper_bound(p);
	if (it != q.end() && it->w1 >= w) return;
	int last = p, last_w = it == q.end() ? 0 : it->w1;
	//fprintf(stderr, "!%d %d %d\n", p, q.begin()->w0, it!=q.begin());
	assert(it != q.begin());
	--it;
	if (q[p] >= w) return;
	for (; ; ) {
		//printf("[%d %d] %d->%d\n", it->w0 + 1, last, last_w, w);
		sum += (last - it->w0) * (w - last_w);
		last_w = it->w1;
		last = it->w0;

		if (it->w1 > w) {
			q[p] = w;
			break;
		} else {
			assert(it != q.begin());
			auto tmp = it;
			--it;
			q.erase(tmp);
		}
	}
	//printf("S: %lld\n", sum);
}

int access(int p) {
	auto it = q.lower_bound(p);
	return it == q.end() ? 0 : it->w1;
}

int main() {
	//freopen("cccc.in", "r", stdin);
	scanf("%d", &n);

	for (int i = 1; i <= W; ++i)
		for (int j = i; j <= W; j += i)
			fac[j].push_back(i);

	for (int i = 1; i <= n; ++i) {
		scanf("%d", &a[i]);
		for (int p : fac[a[i]]) appear[p].push_back(i);
	}

	q[0] = inf;

	for (int i = 1; i <= n; ++i) {
		for (int p : fac[a[i]]) {
			int size = appear[p].size();
			if (size == 1) continue;
			int fi = appear[p][size - 1],
				se = appear[p][size - 2],
				h  = appear[p][0];

			if (se - 1 > 0) update(se - 1, p);
			if (fi - 1 > 0) vec[h + 1].push_back(pii(fi - 1, p));//, printf("!!!!%d %d\n", fi - 1, p);
			vec[appear[p][1] + 1].push_back(pii(n, p));
		}
	}

	for (int i = 1; i <= n; ++i) {
		for (pii t : vec[i]) update(t.w0, t.w1);
			//printf("$%d %lld\n", i, sum);

		ans += sum;
		if (i == 1) ans -= access(n - 1);
		sum -= access(i);
		q[i] = inf;
	}

	printf("%lld\n", ans);
	return 0;
}


#pragma comment(linker, "/STACK:536870912")
#pragma warning(disable:4996)

//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include<iostream>
#include<algorithm>
#include<queue>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<set>
#include<cstring>
#include<ctime>
#include<cassert>
#include<cmath>
#include<limits>
#include<iterator>
#include<functional>
#include<unordered_map>
#include<unordered_set>
#include<stack>
#include<bitset>
#include<complex>

#define all(v) v.begin(), v.end()
#define setv(ar, val) memset(ar, val, sizeof(ar));
#define ll long long int
#define ld long double
#define ull unsigned long long int
#define PI 3.1415926535897932384626433832795
using namespace std;

const int N = 2e5 + 100;
int a[N], up[N * 4], last[N], mn[N * 4];
bool w[N];
ll sum[N * 4];
int n;

void push(int v, int L, int R) {
	if (up[v]) {
		if (L != R)
			up[v * 2] = up[v * 2 + 1] = up[v];
		sum[v] = up[v] * (R - L + 1ll);
		mn[v] = up[v];
		up[v] = 0;
	}
}

void upd(int l, int r, int d, int v, int L, int R) {
	push(v, L, R);
	if (l > r)
		return;
	if (l == L && r == R) {
		up[v] = d;
		push(v, L, R);
	}
	else {
		int m = (L + R) >> 1;
		upd(l, min(m, r), d, v * 2, L, m);
		upd(max(m + 1, l), r, d, v * 2 + 1, m + 1, R);
		sum[v] = sum[v * 2] + sum[v * 2 + 1];
		mn[v] = min(mn[v * 2],mn[v * 2 + 1]);
	}
}

ll queS(int l, int r, int v, int L, int R) {
	push(v, L, R);
	if (l > r)
		return 0;
	if (l == L && r == R)
		return sum[v];
	int m = (L + R) >> 1;
	return queS(l, min(m, r), v * 2, L, m)
		+ queS(max(m + 1, l), r, v * 2 + 1, m + 1, R);
}

int queP(int x, int v, int L, int R) {
	push(v, L, R);
	if (L == R)
		return L;
	int m = (L + R) >> 1;
	if (mn[v * 2] < x)
		return queP(x, v * 2, L, m);
	return queP(x, v * 2 + 1, m + 1, R);

}

void handle(int x) {
	if (!w[x]) {
		w[x] = 1;
		int t = queP(x, 1, 0, n);
		upd(t, last[x], x, 1, 0, n);
	}
}

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	scanf("%d", &n);

	for (int i = 0; i < n; i++)
		scanf("%d", &a[i]);

	ll ans = 0;

	for (int i = n - 1, mx = 0; i >= 0; i--) {
		for (int j = 1; j * j <= a[i]; j++) {
			if (a[i] % j == 0) {
				if (w[j])
					mx = max(mx, j);
				else
					last[j] = i;

				if (w[a[i] / j])
					mx = max(mx, a[i] / j);
				else
					last[a[i] / j] = i;

				w[a[i] / j] = 1;
				w[j] = 1;
			}
		}
		upd(i, i, mx, 1, 0, n);
		if (i)
			ans += mx;
	}

	setv(w, 0);

	int mx = 0;
	for (int i = 0; i < n - 1; i++) {
		for (int j = 1; j * j <= a[i]; j++) {
			if (a[i] % j == 0) {
				if (w[j])
					mx = max(mx, j);
				if (w[a[i] / j])
					mx = max(mx, a[i] / j);
				handle(j), handle(a[i] / j);
			}
		}
		ans += mx;

		ll x = max(queP(mx, 1, 0, n), i + 2);
		ans += mx * (n - x) + queS(i + 2, x - 1, 1, 0, n);
	}

	printf("%lld", ans);

	return 0;
}


#pragma comment(linker, "/STACK:536870912")
#pragma warning(disable:4996)

//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include<iostream>
#include<algorithm>
#include<queue>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<set>
#include<cstring>
#include<ctime>
#include<cassert>
#include<cmath>
#include<limits>
#include<iterator>
#include<functional>
#include<unordered_map>
#include<unordered_set>
#include<stack>
#include<bitset>
#include<complex>

#define all(v) v.begin(), v.end()
#define setv(ar, val) memset(ar, val, sizeof(ar));
#define ll long long int
#define ld long double
#define ull unsigned long long int
#define PI 3.1415926535897932384626433832795
using namespace std;

const int N = 2e5 + 100;
int a[N], up[N * 4], last[N];
bool w[N];
ll sum[N * 4];
int n;

void push(int v, int L, int R) {
	if (up[v]) {
		if (L != R)
			up[v * 2] = up[v * 2 + 1] = up[v];
		sum[v] = up[v] * (R - L + 1ll);
		up[v] = 0;
	}
}

void upd(int l, int r, int d, int v, int L, int R) {
	push(v, L, R);
	if (l > r)
		return;
	if (l == L && r == R) {
		up[v] = d;
		push(v, L, R);
	}
	else {
		int m = (L + R) >> 1;
		upd(l, min(m, r), d, v * 2, L, m);
		upd(max(m + 1, l), r, d, v * 2 + 1, m + 1, R);
		sum[v] = sum[v * 2] + sum[v * 2 + 1];
	}
}

ll queS(int l, int r, int v, int L, int R) {
	push(v, L, R);
	if (l > r)
		return 0;
	if (l == L && r == R)
		return sum[v];
	int m = (L + R) >> 1;
	return queS(l, min(m, r), v * 2, L, m)
		+ queS(max(m + 1, l), r, v * 2 + 1, m + 1, R);
}

int lb(int s, int x) {
	int l = s - 1, r = n;
	while (r - l > 1) {
		int p = (r + l) >> 1;
		if (queS(p, p, 1, 0, n - 1) < x)
			r = p;
		else
			l = p;
	}
	return r;
}

void handle(int x) {
	w[x] = 1;
	int t = lb(0, x);
	upd(t, last[x], x, 1, 0, n - 1);
}

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	scanf("%d", &n);

	for (int i = 0; i < n; i++)
		scanf("%d", &a[i]);

	ll ans = 0;

	for (int i = n - 1, mx = 0; i >= 0; i--) {
		for (int j = 1; j * j <= a[i]; j++) {
			if (a[i] % j == 0) {
				if (w[j])
					mx = max(mx, j);
				else
					last[j] = i;

				if (w[a[i] / j])
					mx = max(mx, a[i] / j);
				else
					last[a[i] / j] = i;

				w[a[i] / j] = 1;
				w[j] = 1;
			}
		}
		upd(i, i, mx, 1, 0, n - 1);
		if (i)
			ans += mx;
	}

	setv(w, 0);

	int mx = 0;
	for (int i = 0; i < n - 1; i++) {
		for (int j = 1; j * j <= a[i]; j++) {
			if (a[i] % j == 0) {
				if (w[j])
					mx = max(mx, j);
				if (w[a[i] / j])
					mx = max(mx, a[i] / j);
				handle(j), handle(a[i] / j);
			}
		}
		ans += mx;

		ll x = lb(i + 2, mx);
		ans += mx * (n - x) + queS(i + 2, x - 1, 1, 0, n - 1);
	}

	printf("%lld", ans);

	return 0;
}


#pragma comment(linker, "/STACK:536870912")
#pragma warning(disable:4996)

//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include<iostream>
#include<algorithm>
#include<queue>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<set>
#include<cstring>
#include<ctime>
#include<cassert>
#include<cmath>
#include<limits>
#include<iterator>
#include<functional>
#include<unordered_map>
#include<unordered_set>
#include<stack>
#include<bitset>
#include<complex>

#define all(v) v.begin(), v.end()
#define setv(ar, val) memset(ar, val, sizeof(ar));
#define ll long long int
#define ld long double
#define ull unsigned long long int
#define PI 3.1415926535897932384626433832795
using namespace std;

const int N = 2e5 + 100;
int a[N], up[N * 4], last[N], mn[N * 4];
bool w[N];
ll sum[N * 4];
int n;

void push(int v, int L, int R) {
	if (up[v]) {
		if (L != R)
			up[v * 2] = up[v * 2 + 1] = up[v];
		sum[v] = up[v] * (R - L + 1ll);
		mn[v] = up[v];
		up[v] = 0;
	}
}

void upd(int l, int r, int d, int v, int L, int R) {
	push(v, L, R);
	if (l > r)
		return;
	if (l == L && r == R) {
		up[v] = d;
		push(v, L, R);
	}
	else {
		int m = (L + R) >> 1;
		upd(l, min(m, r), d, v * 2, L, m);
		upd(max(m + 1, l), r, d, v * 2 + 1, m + 1, R);
		sum[v] = sum[v * 2] + sum[v * 2 + 1];
		mn[v] = min(mn[v * 2],mn[v * 2 + 1]);
	}
}

ll queS(int l, int r, int v, int L, int R) {
	push(v, L, R);
	if (l > r)
		return 0;
	if (l == L && r == R)
		return sum[v];
	int m = (L + R) >> 1;
	return queS(l, min(m, r), v * 2, L, m)
		+ queS(max(m + 1, l), r, v * 2 + 1, m + 1, R);
}

int queP(int x, int v, int L, int R) {
	push(v, L, R);
	if (L == R)
		return L;
	int m = (L + R) >> 1;
	if (mn[v * 2] < x)
		return queP(x, v * 2, L, m);
	return queP(x, v * 2 + 1, m + 1, R);

}

void handle(int x) {
	w[x] = 1;
	int t = queP(x, 1, 0, n);
	upd(t, last[x], x, 1, 0, n);
}

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	scanf("%d", &n);

	for (int i = 0; i < n; i++)
		scanf("%d", &a[i]);

	ll ans = 0;

	for (int i = n - 1, mx = 0; i >= 0; i--) {
		for (int j = 1; j * j <= a[i]; j++) {
			if (a[i] % j == 0) {
				if (w[j])
					mx = max(mx, j);
				else
					last[j] = i;

				if (w[a[i] / j])
					mx = max(mx, a[i] / j);
				else
					last[a[i] / j] = i;

				w[a[i] / j] = 1;
				w[j] = 1;
			}
		}
		upd(i, i, mx, 1, 0, n);
		if (i)
			ans += mx;
	}

	setv(w, 0);

	int mx = 0;
	for (int i = 0; i < n - 1; i++) {
		for (int j = 1; j * j <= a[i]; j++) {
			if (a[i] % j == 0) {
				if (w[j])
					mx = max(mx, j);
				if (w[a[i] / j])
					mx = max(mx, a[i] / j);
				handle(j), handle(a[i] / j);
			}
		}
		ans += mx;

		ll x = max(queP(mx, 1, 0, n), i + 2);
		ans += mx * (n - x) + queS(i + 2, x - 1, 1, 0, n);
	}

	printf("%lld", ans);

	return 0;
}


#include<bits/stdc++.h>
#define rep(i,a,b) for (int i=(a); i<=int(b); i++)
#define lc (o << 1)
#define rc (o << 1 | 1)
#define mid ((l + r) >> 1)
using namespace std;
typedef long long LL;

const int maxn = 200009;
struct segment {
	int mn, mx, lazy; LL sum;
} T[maxn<<2];
vector<pair<int,int> > vec[maxn];
int L[maxn], L2[maxn], R[maxn], R2[maxn];
long long ans;
int n, a;

void calc(int o, int l, int r, int x) {
	if (!x) return;
	T[o].mn = T[o].mx = T[o].lazy = x;
	T[o].sum = 1LL * (r - l + 1) * x;
}

void update(int o, int l, int r, int x, int y, int z) {
	if (z <= T[o].mn || x > y) return;
	if (l == x && y == r && z >= T[o].mx) {
		T[o].mn = T[o].mx = T[o].lazy = z;
		T[o].sum = 1LL * (r - l + 1) * z;
		return;
	}
	calc(lc, l, mid, T[o].lazy);
	calc(rc, mid+1, r, T[o].lazy); T[o].lazy = 0;
	if (x <= mid) update(lc, l, mid, x, min(y, mid), z);
	if (mid+1 <= y) update(rc, mid+1, r, max(mid+1, x), y, z);
	T[o].sum = T[lc].sum + T[rc].sum;
	T[o].mx = max(T[lc].mx, T[rc].mx);
	T[o].mn = min(T[lc].mn, T[rc].mn);
}

LL query(int o, int l, int r, int x, int y) {
	if (l == x && y == r) return T[o].sum;
	calc(lc, l, mid, T[o].lazy);
	calc(rc, mid+1, r, T[o].lazy); T[o].lazy = 0;
	if (y <= mid) return query(lc, l, mid, x, y);
	if (mid+1 <= x) return query(rc, mid+1, r, x, y);
	return query(lc, l, mid, x, mid) + query(rc, mid+1, r, mid+1, y);
}

int main() {
	scanf("%d", &n);
	rep (i, 1, maxn-1) L[i] = L2[i] = n+1;
	rep (i, 1, n) {
		scanf("%d", &a);
		for (int j=1; j*j<=a; j++)
			if (a % j == 0) {
				if (i < L[j]) { L2[j] = L[j]; L[j] = i;}
				else if (i < L2[j]) L2[j] = i;
				if (i > R[j]) { R2[j] = R[j]; R[j] = i; }
				else if (i > R2[j]) R2[j] = i;
				if (j * j == a) continue;
				if (i < L[a/j]) { L2[a/j] = L[a/j]; L[a/j] = i;}
				else if (i < L2[a/j]) L2[a/j] = i;
				if (i > R[a/j]) { R2[a/j] = R[a/j]; R[a/j] = i; }
				else if (i > R2[a/j]) R2[a/j] = i;
			}
	}
	rep (i, 1, maxn-1) {
		if (L[i] + 1 <= R[i] - 1) {
			vec[L[i]+1].push_back(make_pair(R[i]-1, i));
			//printf("!   %d %d %d\n", i, L[i]+1, R[i]-1);
		}
		if (L2[i] <= n-1) {
			vec[L2[i]+1].push_back(make_pair(n, i));
			//printf("@   %d %d %d\n", i, L2[i]+1, n);
		}
		if (R2[i] >= 2) {
			vec[1].push_back(make_pair(R2[i]-1, i));
			//printf("#   %d %d %d\n", i, 1, R2[i]-1);
		}
	}
	rep (i, 1, n) {
		rep (j, 0, vec[i].size()-1)
			update(1, 1, n, i, vec[i][j].first, vec[i][j].second);
		ans += query(1, 1, n, i, n);
	}
	printf("%lld\n", ans);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define lc (x<<1)
#define rc ((x<<1)|1)
//const int N=200000;
const int N=6;
void MIN(int &x,int y){x=min(x,y);}
void MAX(int &x,int y){x=max(x,y);}
int a[N+5],val[N+5][2];
vector<int> fac[N+5];
void init(){
    for (int i=1;i<=N;i++) for (int j=i;j<=N;j+=i) fac[j].pb(i);
    for (int i=1;i<=N;i++) val[i][0]=N+1;
}
struct emt{
    int l,r,v,t,d;
};
emt e[N*6+5];
bool cmp(emt a,emt b){return a.t<b.t;}

struct Node{
    multiset<int> S;
    LL sum;
    Node(){S.insert(0);sum=0;}
};
Node T[(1<<19)+10];
void update(int x,int len){
    auto ii=T[x].S.end();
    T[x].sum=max(1ll * *(--ii) * len,T[lc].sum+T[rc].sum);
}
void modify(int x,int l,int r,int ql,int qr,int v,int d){
    int mid= l+r>>1;
    if (ql<=l&&r<=qr){
        if (d==1) T[x].S.insert(v);
        else T[x].S.erase(v);
        auto ii=T[x].S.end();
        T[x].sum= *(--ii);
        return;
    }
    if (ql<=mid) modify(lc,l,mid,ql,qr,v,d);
    if (mid<qr) modify(rc,mid+1,r,ql,qr,v,d);
    update(x,r-l+1);
}
LL query(int x,int l,int r,int p){
    int mid= l+r>>1;
    if (l==r) return T[x].sum;
    if (p<=mid) return query(lc,l,mid,p);
    else return query(rc,mid+1,r,p);
}
int main(){
   // freopen("in.txt","r",stdin);
    init();
    int i,j,k,n,m;LL ans=0,ans1=0;
    cin>>n;
    for (i=1;i<=n;i++) scanf("%d",a+i),MIN(val[a[i]][0],i),MAX(val[a[i]][1],i);
    for (i=N;i>=1;i--){
        for (int x:fac[i]) MIN(val[x][0],val[i][0]),MAX(val[x][1],val[i][1]);
    }
    for (i=1;i<=N;i++){
        e[i].l=val[i][0]+1,e[i].r=val[i][1]-1,e[i].v=i,e[i].t=e[i].l,e[i].d=1,
        e[N+i]=e[i],e[N+i].t=e[i].r+1,e[N+i].d=-1;
        if (val[i][0]<val[i][1]){
            e[N*2+i].l=1,e[N*2+i].r=val[i][0]-1,e[N*2+i].v=i,e[N*2+i].t=e[N*2+i].l,e[N*2+i].d=1,
            e[N*3+i]=e[N*2+i],e[N*3+i].t=e[N*2+i].r+1,e[N*3+i].d=-1;
            e[N*4+i].l=val[i][1]+1,e[N*4+i].r=n,e[N*4+i].v=i,e[N*4+i].t=e[N*4+i].l,e[N*4+i].d=1,
            e[N*5+i]=e[N*4+i],e[N*5+i].t=e[N*4+i].r+1,e[N*5].d=-1;
        } else e[N*2+i].t=e[N*3+i].t=e[N*4+i].t=e[N*5+i].t=N+1;
    }
    sort(e+1,e+N*6+1,cmp);e[N*6+1].t=N+1;
 //for (i=1;i<=6;i++) printf("%d %d\n",val[i][0],val[i][1]);puts("");
 //for (i=1;i<=36;i++) printf("%d : %d %d %d %d\n",e[i].t,e[i].l,e[i].r,e[i].v,e[i].d);
    for (j=1;e[j].t<1;j++);
    for (i=1;i<=n;i++){
        for (k=j;e[k].t==i;k++);
        for (;j<k;j++) if (e[j].l<=e[j].r) modify(1,1,n,e[j].l,e[j].r,e[j].v,e[j].d);
        ans += T[1].sum;
        ans1 += query(1,1,n,i);
   //     cout<< T[1].sum <<endl;
    }
  //  cout<<e[1].t<<endl;
  //  puts("");
  //  cout<<ans<<" "<<ans1<<endl;
    ans=(ans-ans1)/2+ans1;
    cout<<ans<<endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define fr first
#define sc second
#define lc (x<<1)
#define rc ((x<<1)|1)
const int N=200000;
//const int N=6;
struct emt{
    int t,l,r,v,d;
};
emt e[N*6+5];
bool cmp(emt a,emt b){
    if (a.t!=b.t) return a.t<b.t;
    if (a.d!=b.d) return a.d<b.d;
    return a.v>b.v;
}
void setval(emt &e,int l,int r,int v,int t,int d){e.l=l,e.r=r,e.v=v,e.t=t,e.d=d;}
int val[N+5][4];
vector<int> fac[N+5];
void MIN(int x,int v){
    if (val[x][0]>v) val[x][1]=val[x][0],val[x][0]=v;
    else if (val[x][0]!=v&&val[x][1]>v) val[x][1]=v;
}
void MAX(int x,int v){
    if (val[x][3]<v) val[x][2]=val[x][3],val[x][3]=v;
    else if (val[x][3]!=v&&val[x][2]<v) val[x][2]=v;
}
multiset<int> a[N+5];
int BIG(int x){return *(a[x].rbegin());}
map<int,int> S;
int SBIG(){return S.rbegin()->sc;}
void init(){
    for (int i=1;i<=N;i++) for (int j=i;j<=N;j+=i) fac[j].pb(i);
    for (int i=1;i<=N;i++) val[i][0]=val[i][1]=N+1,a[i].insert(0);
    S.insert(mp(0,0));
}

LL sum;
int key[(1<<19)+10];
int ql,qr,p,v,n;
pii pr;
void update(int x){key[x]=max(key[lc],key[rc]);}
void modify(int x,int l,int r){
    int mid= l+r>>1;
    if (l==r) {key[x]=v;return;}
    if (p<=mid) modify(lc,l,mid);
    else modify(rc,mid+1,r);
    update(x);
}
void query(int x,int l,int r){
    int mid= l+r>>1;
    if (ql<=l&&r<=qr){
        if (key[x]>v){
            if (l==r) {pr=mp(l,key[x]);return;}
            if (key[lc]>v) query(lc,l,mid);
            else query(rc,mid+1,r);
        }
        return;
    }
    if (ql<=mid) query(lc,l,mid);
    if (!pr.fr) if (mid<qr) query(rc,mid+1,r);
}
void MODIFY(emt e,bool FIRST){
    p=e.l,v=e.v;
    if (e.d==1){
        if (FIRST){
            modify(1,1,n);
            if (SBIG()<v) S.insert(mp(p,v));
        }
        a[p].insert(v);
    } else{
        a[p].erase(a[p].find(v));
        int BB=BIG(p);if (BB>=v) return;
        v=BB,modify(1,1,n);
        auto tp=S.find(p);
        if (tp==S.end()) return;
        auto sp=tp,rp=tp;sp--;rp++;
        int rz = (rp==S.end())?e.t:rp->fr;
        int len = rz - tp->fr;v=e.v;
        if (BB > sp->sc) tp->sc=BB; else swap(tp,sp),S.erase(sp);
        sum-=1ll*len*(v - tp->sc);
        pr = *tp;
        while (1){
            ql=pr.fr+1,qr=rz-1,v=pr.sc;
            if (ql>qr) return;
            pr.fr=0;query(1,1,n);
            if (pr.fr) S.insert(pr),sum+=1ll*(qr-pr.fr+1)*(pr.sc-v);
            else return;
        }
    }
}
int main(){
   // freopen("in.txt","r",stdin);
    init();
    int i,j,k;
    cin>>n;
    for (i=1;i<=n;i++) {int x;scanf("%d",&x),MIN(x,i),MAX(x,i);}
    for (i=N;i>=1;i--) for (int x:fac[i])
        MIN(x,val[i][0]),MIN(x,val[i][1]),
        MAX(x,val[i][3]),MAX(x,val[i][2]);
    int tot=0;
    for (i=1;i<=N;i++){
        if (val[i][0]+1<=val[i][3]-1)
            setval(e[++tot],val[i][0]+1,val[i][3]-1,i,val[i][0]+1,1),
            setval(e[++tot],val[i][0]+1,val[i][3]-1,i,val[i][3],-1);
        if (val[i][2]>1)
            setval(e[++tot],1,val[i][2]-1,i,1,1),
            setval(e[++tot],1,val[i][2]-1,i,val[i][2],-1);
        if (val[i][1]<n)
            setval(e[++tot],val[i][1]+1,n,i,val[i][1]+1,1),
            setval(e[++tot],val[i][1]+1,n,i,n+1,-1);
    }
    sort(e+1,e+tot+1,cmp);e[tot+1].t=N+1;
 //   for (i=1;i<=tot;i++) printf("%d : %d %d %d %d\n",e[i].t,e[i].l,e[i].r,e[i].v,e[i].d);
    LL ans=0;
    for (i=1,j=1;i<=n;i++){
        for (k=j;e[k].t==i;k++);
        for (;j<k;j++) if (e[j].l<=e[j].r) MODIFY(e[j],e[j-1].t!=i||e[j-1].d==-1);
        sum+=1ll*SBIG();ans+=sum;//cout<<sum<<endl;
    }
    cout<<ans<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define fr first
#define sc second
#define lc (x<<1)
#define rc ((x<<1)|1)
const int N=200000;
//const int N=6;
struct emt{
    int l,r,v,t,d;
};
emt e[N*6+5];
bool cmp(emt a,emt b){
    if (a.t!=b.t) return a.t<b.t;
    if (a.d!=b.d) return a.d<b.d;
    return a.v>b.v;
}
void setval(emt &e,int l,int r,int v,int t,int d){e.l=l,e.r=r,e.v=v,e.t=t,e.d=d;}
int val[N+5][4];
vector<int> fac[N+5];
void MIN(int x,int v){
    if (val[x][0]>v) val[x][1]=val[x][0],val[x][0]=v;
    else if (val[x][0]!=v&&val[x][1]>v) val[x][1]=v;
}
void MAX(int x,int v){
    if (val[x][3]<v) val[x][2]=val[x][3],val[x][3]=v;
    else if (val[x][3]!=v&&val[x][2]<v) val[x][2]=v;
}
multiset<int> a[N+5];
int BIG(int x){return *(a[x].rbegin());}
map<int,int> S;
int SBIG(){return S.rbegin()->sc;}
void init(){
    for (int i=1;i<=N;i++) for (int j=i;j<=N;j+=i) fac[j].pb(i);
    for (int i=1;i<=N;i++) val[i][0]=val[i][1]=N+1,a[i].insert(0);
    S.insert(mp(0,0));
}

LL sum;
int key[(1<<19)+10];
int ql,qr,p,v,d,n;
pii pr;

void update(int x){key[x]=max(key[lc],key[rc]);}
void modify(int x,int l,int r){
    int mid= l+r>>1;
    if (l==r) {key[x]=v;return;}
    if (p<=mid) modify(lc,l,mid);
    else modify(rc,mid+1,r);
    update(x);
}
void query(int x,int l,int r){
    int mid= l+r>>1,ans1=0,ans2=0;
    if (ql<=l&&r<=qr){
        if (key[x]>v){
            if (l==r) {pr=mp(l,key[x]);return;}
            if (key[lc]>v) query(lc,l,mid);
            else query(rc,mid+1,r);
        }
        return;
    }
    if (ql<=mid) query(lc,l,mid);
    if (!pr.fr) if (mid<qr) query(rc,mid+1,r);
}
void MODIFY(emt e,bool FIRST){
    p=e.l,v=e.v,d=e.d;
    if (d==1){
        if (FIRST){
            modify(1,1,n);
            if (SBIG()<v) S.insert(mp(p,v));
        }
        a[p].insert(v);
    } else{
        a[p].erase(a[p].find(v));
        int BB=BIG(p);
        if (BB>=v) return;
        auto tp=S.find(p);
        if (tp==S.end()) return;
        auto sp=tp,rp=tp;sp--;rp++;
        int rz = (rp==S.end())?e.t:rp->fr;
        int len = rz - tp->fr;
        if (BB > sp->sc) tp->sc=BB; else swap(tp,sp),S.erase(sp);
        sum-=1ll*len*(v - tp->sc);v=BB,modify(1,1,n);

        pr = *tp;
        while (1){
            ql=pr.fr+1,qr=rz-1,v=pr.sc;
            if (ql>qr) return;
            pr.fr=0;query(1,1,n);
            if (pr.fr) S.insert(pr),sum+=1ll*(qr-pr.fr+1)*(pr.sc-v);
            else return;
        }
    }
}
int main(){
    //freopen("in.txt","r",stdin);
    init();
    int i,j,k;
    cin>>n;
    for (i=1;i<=n;i++) {int x;scanf("%d",&x),MIN(x,i),MAX(x,i);}
    for (i=N;i>=1;i--) for (int x:fac[i])
        MIN(x,val[i][0]),MIN(x,val[i][1]),
        MAX(x,val[i][3]),MAX(x,val[i][2]);
    int tot=0;
    for (i=1;i<=N;i++){
        if (val[i][0]+1<=val[i][3]-1)
            setval(e[++tot],val[i][0]+1,val[i][3]-1,i,val[i][0]+1,1),
            setval(e[++tot],val[i][0]+1,val[i][3]-1,i,val[i][3],-1);
        if (val[i][2]>1)
            setval(e[++tot],1,val[i][2]-1,i,1,1),
            setval(e[++tot],1,val[i][2]-1,i,val[i][2],-1);
        if (val[i][1]<n)
            setval(e[++tot],val[i][1]+1,n,i,val[i][1]+1,1),
            setval(e[++tot],val[i][1]+1,n,i,n+1,-1);
    }
    sort(e+1,e+tot+1,cmp);e[tot+1].t=N+1;
 //   for (i=1;i<=tot;i++) printf("%d : %d %d %d %d\n",e[i].t,e[i].l,e[i].r,e[i].v,e[i].d);
    LL ans=0;
    for (i=1,j=1;i<=n;i++){
        for (k=j;e[k].t==i;k++);
        for (;j<k;j++) if (e[j].l<=e[j].r) MODIFY(e[j],e[j-1].t!=i||e[j-1].d==-1);
        sum+=1ll*SBIG();ans+=sum;//cout<<sum<<endl;
    //    if (i==2) {for (int i=1;i<=5;i++) printf("%d ",key[i]);puts("");}
      //  if (i==2) cout<<SBIG()<<endl;
    }
    cout<<ans<<endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define FOR(i,n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<ii> vii;

const int MX = 200005;

struct ST {
	ll st[4*MX], lz[4*MX], mn[4*MX];

	void init (int i, int j, int pos) {
		lz[pos] = 0;

		if (i == j) {
			st[pos] = i;
			mn[pos] = i;
			return;
		}

		int m = (i+j)/2;
		init(i, m, pos*2);
		init(m+1, j, pos*2+1);

		st[pos] = st[pos*2] + st[pos*2+1];
		mn[pos] = min(mn[pos*2], mn[pos*2+1]);
	}

	void upLazy (int i, int j, int pos) {
		st[pos] = lz[pos] * (j - i + 1);
		mn[pos] = lz[pos];

		if (i < j) {
			lz[pos*2] = lz[pos];
			lz[pos*2+1] = lz[pos];
		}

		lz[pos] = 0;
	}

	void update (int i, int j, int pos, int a, int b, int k) {
		if (lz[pos])
			upLazy(i, j, pos);

		if (j < a || b < i)
			return;

		if (a <= i && j <= b) {
			lz[pos] = k;
			upLazy(i, j, pos);
			return;
		}

		int m = (i+j)/2;
		update(i, m, pos*2, a, b, k);
		update(m+1, j, pos*2+1, a, b, k);

		st[pos] = st[pos*2] + st[pos*2+1];
		mn[pos] = min(mn[pos*2], mn[pos*2+1]);
	}

	int find (int i, int j, int pos, int k) {
		if (lz[pos])
			upLazy(i, j, pos);

		if (i == j) {
			if (st[pos] <= k)
				return i;
			return -1;
		}

		int m = (i+j)/2;
		if (mn[pos*2+1] <= k)
			return find(m+1, j, pos*2+1, k);
		return find(i, m, pos*2, k);
	}
}st;

vi adj[MX];
int n, a[MX], x;
ll res = 0, acu[MX];

void update (int i) {
	vi &v = adj[i];

	if (v.size() < 2)
		return;

	if (v[1] < n)
		st.update(1, n, 1, v[1] + 1, n, n + 1);

	int d = st.find(1, n, 1, v.back() - 1);
	if (v[0] + 1 <= min(d, v[1]));
		st.update(1, n, 1, v[0] + 1, min(d, v[1]), v.back());

	d = st.find(1, n, 1, v[v.size()-2] - 1);
	if (d >= 1)
		st.update(1, n, 1, 1, min(d, v[0]), v[v.size()-2]);
}

int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);

	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> x;
		a[x] = i;
	}

	for (int i = 1; i < MX; i++) {
		for (int j = i; j < MX; j += i)
			if (a[j])
				adj[i].push_back(a[j]);
		sort(ALL(adj[i]));
	}

	st.init(1, n, 1);

	for (int i = MX - 1; i >= 0; i--) {
		acu[i] = ll(n) * (n + 1) - st.st[1];
		update(i);
	}

	for (int i = 1; i < MX; i++) {
		if (acu[i] - acu[i-1]) {
			//cout << i << " " << acu[i] - acu[i-1] << endl;
		}
		res += i * (acu[i] - acu[i-1]);
	}

	cout << res << endl;

	return 0;
}


#include<cstdio>
#define lld long long
#include<map>
#include<algorithm>
#include<vector>
#define pb push_back
#define ff first
#include<iostream>
#include<cmath>
#include<vector>
#define ss second
using namespace std;
const int maxn=2e5;
vector<int>vect[maxn+10];
lld tree[4*maxn],cnt[4*maxn],lazy[4*maxn],h[maxn+10];
int mn1[4*maxn],mn2[4*maxn],n,maxx,inf=1e9;
void proces(int x,int id){

   for(int i=1;i*i<=x;i++){
    if(x%i>0)continue;
    vect[i].pb(id);
    if(i==x/i)continue;
    vect[x/i].pb(id);
   }
}
void mrg(int x,int y1,int y2){

   tree[x]=tree[y1]+tree[y2];
   mn1[x]=min(mn1[y1],mn1[y2]);
   if(mn1[y1]==mn1[x] && mn1[y2]==mn1[x])mn2[x]=min(mn2[y1],mn2[y2]);
   else mn2[x]=min(max(mn1[y1],mn1[y2]),min(mn2[y1],mn2[y2]));
   cnt[x]=0;
   if(mn1[y1]==mn1[x])cnt[x]+=cnt[y1];
   if(mn1[y2]==mn1[x])cnt[x]+=cnt[y2];
}
void build(int x,int l,int r){
   if(l==r){
    mn1[x]=l;
    mn2[x]=inf;
    lazy[x]=0;
    tree[x]=l;
    cnt[x]=1;
    return;
   }
   int mid=(l+r)/2;
   build(x*2,l,mid);
   build(x*2+1,mid+1,r);
   mrg(x,x*2,x*2+1);
}
void fix(int x,int y){

   tree[y]+=cnt[y]*lazy[x];
   mn1[y]+=lazy[x];
   lazy[y]+=lazy[x];
}
void push(int x){
   if(lazy[x]==0)return;

   if(mn1[x*2+1]==mn1[x*2]){
    fix(x,x*2);
    fix(x,x*2+1);
   }
   else{
     if(mn1[x*2]<mn1[x*2+1])fix(x,x*2);
     else fix(x,x*2+1);
   }

   lazy[x]=0;
}
void update(int x,int l,int r,int ll,int rr,int val){
   if(l>rr || r<ll || val<=mn1[x])return;
   if(l>=ll && r<=rr && val<mn2[x]){
    ///printf("%d %d %d %d %d\n",l,r,ll,rr,val);
    tree[x]+=cnt[x]*(val-mn1[x]);
    lazy[x]+=(val-mn1[x]);
    mn1[x]=val;
    return;
   }
   int mid=(l+r)/2;
   push(x);
   update(x*2,l,mid,ll,rr,val);
   update(x*2+1,mid+1,r,ll,rr,val);
   mrg(x,x*2,x*2+1);
}
void ispisi(int x,int l,int r){
   printf("%d %d  =  %lld %d %d %lld\n",l,r,tree[x],mn1[x],mn2[x],cnt[x]);
   if(l==r){
    ///printf("%lld ",tree[x]);
    return;
   }
   int mid=(l+r)/2;
   push(x);
   ispisi(x*2,l,mid);
   ispisi(x*2+1,mid+1,r);
   mrg(x,x*2,x*2+1);
}
int main(){

    ///freopen("test.txt","r",stdin);

   scanf("%d",&n);
   for(int i=1;i<=n;i++){
    int a;
    scanf("%d",&a);
    proces(a,i);
    maxx=max(a,maxx);
   }

   build(1,1,n);

   lld pom=n*(n+1);

   for(int i=maxx;i>=0;i--){

      h[i]=pom-tree[1];

      ///cout<<tree[1]<<" aaaa "<<i<<endl;

      if(vect[i].size()<=1)continue;
      int sz=vect[i].size()-1;

      ///ispisi(1,1,n);
      ///printf("\n");

      ///printf(" 1st UPDATE  %d %d %d\n",vect[i][0]+1,vect[i][1],vect[i][sz]);
      update(1,1,n,vect[i][0]+1,vect[i][1],vect[i][sz]);
      ///ispisi(1,1,n);
      ///printf("\n");

      ///printf(" 2nd UPDATE  %d %d %d\n",1,vect[i][0],vect[i][sz-1]);
      update(1,1,n,1,vect[i][0],vect[i][sz-1]);
      ///ispisi(1,1,n);
      ///printf("\n");

      ///printf(" 3nd UPDATE  %d %d %d\n",vect[i][1]+1,n,n+1);
      update(1,1,n,vect[i][1]+1,n,n+1);
      ///ispisi(1,1,n);
      ///printf("\n");

      ///printf("%lld %d %lld\n",h[i],i,tree[1]);
   }
   lld rez=0;
   for(int i=maxx;i>0;i--){
    rez+=i*(h[i]-h[i-1]);
    ///printf("%d %lld\n",i,h[i]-h[i-1]);
   }
   printf("%lld\n",rez);

return 0;
}


#include<cstdio>
#define lld long long
#include<map>
#include<algorithm>
#include<vector>
#define pb push_back
#define ff first
#include<iostream>
#include<cmath>
#define ss second
using namespace std;
int rez[2010],l[2010],r[2010],br,br1[2010];
int main(){

   /// freopen("test.txt","r",stdin);

   string s;
   cin>>s;

   int n=0;
   int k=0;
   int mn=0;
   int mk=0;

   int le=0;
   int ri=-1;
   for(int i=0;i<s.size()-1;i++){
      if(s[i]=='1' && s[i+1]=='0'){
        ri=i;
        l[++br]=le;
        r[br]=ri;
        le=i+1;
      }
   }
   l[++br]=le;
   r[br]=s.size()-1;

   int maxx=0;
   int ck=0;
   int cn=0;
   for(int i=1;i<=br;i++){
    int ll=l[i];
    int rr=r[i];

    for(int j=ll;j<=rr;j++){
        if(s[j]=='0'){
            n++;
            mn++;
        }
        else{
            k++;
            mk=max(mk+1,mn+1);
        }
    }
    ck++;
    cn+=rr-ll;
    if(i==br){
        ck--;
        cn++;
    }

    int gk=k-ck;
    int gn=n-cn;
    maxx=max(maxx,rr-ll+1);
    int gg=max(mk,mn)-maxx;

    ///printf("%d %d %d\n",gn,gk,gg);

    br1[i]=min(gk,min(gn,gg));

   }

   for(int i=1;i<br;i++){
    rez[r[i]]=1;
    for(int j=r[i]-1;j>=l[i] && br1[i]>0;j--){
       br1[i]--;
       rez[j]=1;
    }
   }
   for(int j=r[br];j>=l[br] && br1[br]>0;j--){
       br1[br]--;
       rez[j]=1;
    }

   for(int i=0;i<s.size();i++)printf("%d",rez[i]);

return 0;
}


#include<cstdio>
#define lld long long
#include<map>
#include<algorithm>
#include<vector>
#define pb push_back
#define ff first
#include<iostream>
#include<cmath>
#include<vector>
#define ss second
using namespace std;
const int maxn=2e5;
vector<int>vect[maxn+10];
lld tree[4*maxn],cnt[4*maxn],lazy[4*maxn],h[maxn+10];
int mn1[4*maxn],mn2[4*maxn],n,maxx,inf=1e9;
void proces(int x,int id){

   for(int i=1;i*i<=x;i++){
    if(x%i>0)continue;
    vect[i].pb(id);
    if(i==x/i)continue;
    vect[x/i].pb(id);
   }
}
void mrg(int x,int y1,int y2){

   tree[x]=tree[y1]+tree[y2];
   mn1[x]=min(mn1[y1],mn1[y2]);
   if(mn1[y1]==mn1[x] && mn1[y2]==mn1[x])mn2[x]=min(mn2[y1],mn2[y2]);
   else mn2[x]=max(mn1[y1],mn1[y2]);
   if(mn1[y1]==mn1[x])cnt[x]+=cnt[y1];
   if(mn1[y2]==mn1[x])cnt[x]+=cnt[y2];
}
void build(int x,int l,int r){
   if(l==r){
    mn1[x]=l;
    mn2[x]=inf;
    lazy[x]=0;
    tree[x]=l;
    cnt[x]=1;
    return;
   }
   int mid=(l+r)/2;
   build(x*2,l,mid);
   build(x*2+1,mid+1,r);
   mrg(x,x*2,x*2+1);
}
void fix(int x,int y){

   tree[y]+=cnt[y]*lazy[x];
   mn1[y]+=lazy[x];
   lazy[y]+=lazy[x];
}
void push(int x){
   if(lazy[x]==0)return;

   if(mn1[x]==mn1[x*2])fix(x,x*2);
   if(mn1[x]==mn1[x*2+1])fix(x,x*2+1);

   lazy[x]=0;
}
void update(int x,int l,int r,int ll,int rr,int val){
   if(l>rr || r<ll || val<=mn1[x])return;
   if(l>=ll && r<=rr && val<mn2[x]){
    ///printf("%d %d %d %d %d\n",l,r,ll,rr,val);
    tree[x]+=cnt[x]*(val-mn1[x]);
    lazy[x]+=(val-mn1[x]);
    mn1[x]=val;
    return;
   }
   int mid=(l+r)/2;
   push(x);
   update(x*2,l,mid,ll,rr,val);
   update(x*2+1,mid+1,r,ll,rr,val);
   mrg(x,x*2,x*2+1);
}
int main(){

   /// freopen("test.txt","r",stdin);

   scanf("%d",&n);
   for(int i=1;i<=n;i++){
    int a;
    scanf("%d",&a);
    proces(a,i);
    maxx=max(a,maxx);
   }

   build(1,1,n);

   lld pom=n*(n+1);

   for(int i=maxx;i>=0;i--){

      h[i]=pom-tree[1];

      ///cout<<tree[1]<<" aaaa "<<i<<endl;

      if(vect[i].size()<=1)continue;
      int sz=vect[i].size()-1;

      ///printf(" 1st UPDATE\n");
      update(1,1,n,vect[i][0]+1,vect[i][1],vect[i][sz]);
       ///printf(" 2nd UPDATE\n");
      update(1,1,n,1,vect[i][0],vect[i][sz-1]);
      update(1,1,n,vect[i][1]+1,n,n+1);

      ///printf("%lld %d\n",h[i],i);
   }
   lld rez=0;
   for(int i=maxx;i>0;i--){
    rez+=i*(h[i]-h[i-1]);
    ///printf("%d %lld\n",i,h[i]-h[i-1]);
   }
   printf("%lld\n",rez);

return 0;
}


#include<cstdio>
#define lld long long
#include<map>
#include<algorithm>
#include<vector>
#define pb push_back
#define ff first
#include<iostream>
#include<cmath>
#include<vector>
#define ss second
using namespace std;
const int maxn=2e5;
vector<int>vect[maxn+10];
lld tree[4*maxn],cnt[4*maxn],lazy[4*maxn],h[maxn+10];
int mn1[4*maxn],mn2[4*maxn],n,maxx,inf=1e9;
void proces(int x,int id){

   for(int i=1;i*i<=x;i++){
    if(x%i>0)continue;
    vect[i].pb(id);
    if(i==x/i)continue;
    vect[x/i].pb(id);
   }
}
void mrg(int x,int y1,int y2){

   tree[x]=tree[y1]+tree[y2];
   mn1[x]=min(mn1[y1],mn1[y2]);
   if(mn1[y1]==mn1[x] && mn1[y2]==mn1[x])mn2[x]=min(mn2[y1],mn2[y2]);
   else mn2[x]=min(max(mn1[y1],mn1[y2]),min(mn2[y1],mn2[y2]));
   cnt[x]=0;
   if(mn1[y1]==mn1[x])cnt[x]+=cnt[y1];
   if(mn1[y2]==mn1[x])cnt[x]+=cnt[y2];
}
void build(int x,int l,int r){
   if(l==r){
    mn1[x]=l;
    mn2[x]=inf;
    lazy[x]=0;
    tree[x]=l;
    cnt[x]=1;
    return;
   }
   int mid=(l+r)/2;
   build(x*2,l,mid);
   build(x*2+1,mid+1,r);
   mrg(x,x*2,x*2+1);
}
void fix(int x,int y){

   tree[y]+=cnt[y]*lazy[x];
   mn1[y]+=lazy[x];
   lazy[y]+=lazy[x];
}
void push(int x){
   if(lazy[x]==0)return;

   if(mn1[x*2+1]==mn1[x*2]){
    fix(x,x*2);
    fix(x,x*2+1);
   }
   else{
     if(mn1[x*2]<mn1[x*2+1])fix(x,x*2+1);
     else fix(x,x*2);
   }

   lazy[x]=0;
}
void update(int x,int l,int r,int ll,int rr,int val){
   if(l>rr || r<ll || val<=mn1[x])return;
   if(l>=ll && r<=rr && val<mn2[x]){
    ///printf("%d %d %d %d %d\n",l,r,ll,rr,val);
    tree[x]+=cnt[x]*(val-mn1[x]);
    lazy[x]+=(val-mn1[x]);
    mn1[x]=val;
    return;
   }
   int mid=(l+r)/2;
   push(x);
   update(x*2,l,mid,ll,rr,val);
   update(x*2+1,mid+1,r,ll,rr,val);
   mrg(x,x*2,x*2+1);
}
void ispisi(int x,int l,int r){
  /// printf("%d %d  =  %lld %d %d %lld\n",l,r,tree[x],mn1[x],mn2[x],cnt[x]);
   if(l==r){
    return;
   }
   int mid=(l+r)/2;
   push(x);
   ispisi(x*2,l,mid);
   ispisi(x*2+1,mid+1,r);
   mrg(x,x*2,x*2+1);
}
int main(){

    ///freopen("test.txt","r",stdin);

   scanf("%d",&n);
   for(int i=1;i<=n;i++){
    int a;
    scanf("%d",&a);
    proces(a,i);
    maxx=max(a,maxx);
   }

   build(1,1,n);

   lld pom=n*(n+1);

   for(int i=maxx;i>=0;i--){

      h[i]=pom-tree[1];

      ///cout<<tree[1]<<" aaaa "<<i<<endl;

      if(vect[i].size()<=1)continue;
      int sz=vect[i].size()-1;

      ///ispisi(1,1,n);
      ///printf("\n");

      ///printf(" 1st UPDATE\n");
      update(1,1,n,vect[i][0]+1,vect[i][1],vect[i][sz]);
       ///printf(" 2nd UPDATE\n");
      update(1,1,n,1,vect[i][0],vect[i][sz-1]);
      update(1,1,n,vect[i][1]+1,n,n+1);

      ///printf("%lld %d %lld\n",h[i],i,tree[1]);
   }
   lld rez=0;
   for(int i=maxx;i>0;i--){
    rez+=i*(h[i]-h[i-1]);
    ///printf("%d %lld\n",i,h[i]-h[i-1]);
   }
   printf("%lld\n",rez);

return 0;
}


#include <bits/stdc++.h>
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
*/
#define ll long long
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define IOS ios_base::sync_with_stdio(0);

using namespace std;

const int maxn=2e5+123,INF=1e9,mod=1e9+7,N=2e5+123;
int n,a[maxn],pre[maxn],suf[maxn],last[maxn];
vector< int > v[maxn];
ll t[4*maxn];
int val[4*maxn],mx[4*maxn],mn[4*maxn];
bool was[maxn];
ll ans;
void push(int v,int tl,int tr,int tm){
	if( val[v]==-1 )
		return;
	mn[v+v]=mx[v+v]=val[v+v]=val[v];
	mn[v+v+1]=mx[v+v+1]=val[v+v+1]=val[v];
	t[v+v]=1ll*(tm-tl+1)*val[v];
	t[v+v+1]=1ll*(tr-tm)*val[v];
	val[v]=-1;
}
void upd(int v,int tl,int tr,int l,int r,int x){
	if(l>r)
		return ;
	if( mn[v] >= x )
		return ;
	if(tl==l && tr==r){
		if( mx[v] <= x ){
			mx[v] = x;
			mn[v] = x;
			val[v] = x;
			t[v] = 1ll*x*(tr-tl+1);
			return;
		}
	}
	int tm=(tl+tr)/2;
	push(v,tl,tr,tm);
	upd(v+v,tl,tm,l,min(tm,r),x);
	upd(v+v+1,tm+1,tr,max(tm+1,l),r,x);
	t[v] = t[v+v] + t[v+v+1];
	mx[v] = max(mx[v+v],mx[v+v+1]);
	mn[v] = min(mn[v+v],mn[v+v+1]);
}
ll get(int v,int tl,int tr,int l,int r){
	if( l>r)
		return 0;
	if( tl==l && tr==r )
		return t[v];
	int tm=(tl+tr)/2;
	push(v,tl,tr,tm);
	return get(v+v,tl,tm,l,min(tm,r))+get(v+v+1,tm+1,tr,max(tm+1,l),r);
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		for(int j=1;j*j<=a[i];j++)
			if(a[i]%j==0){
				v[i].pb(j);
				if(j*j!=a[i])
                	v[i].pb(a[i]/j);
			}
		sort(v[i].begin(),v[i].end());
		for( auto x:v[i] )
			last[x]=i;
	}

	for(int i=n;i>=1;i--){
		suf[i]=suf[i+1];
		for( auto x:v[i] ){
			if( was[x] )
				suf[i] = max(suf[i],x) ;
		  	was[x] = 1;
		}
		upd(1,1,n,1,i,suf[i]);
		ans+=suf[i];
	}
	for(int i=1;i<N;i++)
		was[i]=0;
    for(int i=1;i<=n;i++){
		pre[i]=pre[i-1];
		for( auto x:v[i] ){
			if( was[x] )
				pre[i] = max(pre[i],x) ;
		  	was[x]=1;
		}
		ans+=pre[i];
	}

	for(int i=1;i<=n;i++){
		upd(1,1,n,1,n,pre[i]);
		for( auto x:v[i] )
			upd(1,1,n,1,last[x],x);
		ans+=get(1,1,n,i+2,n);
	}

	printf("%lld",ans - 2*pre[n] );
}


#include<bits/stdc++.h>
#define pb push_back

using namespace std;
using INT=long long;
using VI=vector<int>;

#define NN 202020
#define MM 524288
#define ls (u<<1)
#define rs (ls|1)
#define mid (L+R>>1)

VI vec[NN], pos[NN];
int mn[MM], mx[MM], flag[MM];
INT sum[MM], ans[MM];
int l, r, x, n;

void push_up(int u) {
	sum[u]=sum[ls]+sum[rs];
	mx[u]=max(mx[ls], mx[rs]);
	mn[u]=min(mn[ls], mn[rs]);
}

void build(int u, int L, int R) {
	if(R-L>1) {
		flag[u]=NN;
		build(ls, L, mid);
		build(rs, mid, R);
		push_up(u);
	}
	else {
		mn[u]=mx[u]=sum[u]=n-L+1;
	}
}

void smin(int u, int len, int x) {
	mn[u]=mx[u]=x;
	sum[u]=(INT)x*len;
	flag[u]=min(flag[u], x);
}
void push_down(int u, int L, int R) {
	if(flag[u]<NN) {
		smin(ls, mid-L, flag[u]);
		smin(rs, R-mid, flag[u]);
		flag[u]=NN;
	}
}

void update(int u, int L, int R) {
	if(mx[u]<=x) return ;
	if(r<=L || R<=l) return ;
	if(l<=L && R<=r && mn[u]>=x) {
		smin(u, R-L, x); return;
	}
	push_down(u, L, R);
	update(ls, L, mid);
	update(rs, mid, R);
	push_up(u);
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif

	for(int i=1; i<NN; i++) {
		for(int j=i; j<NN; j+=i) vec[j].pb(i);
	}

	scanf("%d", &n);
	build(1, 1, n+1);

	for(int i=1; i<=n; i++) {
		int u; scanf("%d", &u);
		for(int x: vec[u]) pos[x].pb(i);
	}

	for(int u=200001; u; u--) {
		if(pos[u].size()>1) {
			l=1, r=pos[u][0]+1, x=n-pos[u][pos[u].size()-2]+1;
			update(1, 1, n+1);

			l=r, r=pos[u][1]+1, x=n-pos[u].back()+1;
			update(1, 1, n+1);

			l=r, r=n+1, x=0;
			update(1, 1, n+1);
		}
		ans[u]=sum[1];
	}

	INT s=0;
	for(int i=200000; i; i--) {
		s+=(INT)i*(ans[i+1]-ans[i]);
	}
	printf("%I64d", s);
}


#include<bits/stdc++.h>
#define pb push_back

using namespace std;
using INT=long long;
using VI=vector<int>;

#define NN 202020
#define MM 524288
#define ls (u<<1)
#define rs (ls|1)
#define mid (L+R>>1)

VI vec[NN], pos[NN];
int mn[MM], mx[MM], flag[MM];
int l, r, x, n;
INT sum[MM];

void push_up(int u) {
	sum[u]=sum[ls]+sum[rs];
	mx[u]=max(mx[ls], mx[rs]);
	mn[u]=min(mn[ls], mn[rs]);
}

void build(int u, int L, int R) {
	if(R-L>1) {
		flag[u]=NN;
		build(ls, L, mid);
		build(rs, mid, R);
		push_up(u);
	}
	else {
		mn[u]=mx[u]=sum[u]=n-L+1;
	}
}

void smin(int u, int len, int x) {
	mn[u]=mx[u]=x;
	sum[u]=(INT)x*len;
	flag[u]=min(flag[u], x);
}
void push_down(int u, int L, int R) {
	if(flag[u]<NN) {
		smin(ls, mid-L, flag[u]);
		smin(rs, R-mid, flag[u]);
		flag[u]=NN;
	}
}

void update(int u, int L, int R) {
	if(mx[u]<=x) return ;
	if(r<=L || R<=l) return ;
	if(l<=L && R<=r && mn[u]>=x) {
		smin(u, R-L, x); return;
	}
	push_down(u, L, R);
	update(ls, L, mid);
	update(rs, mid, R);
	push_up(u);
}
int ans[NN];

int main() {
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif

	for(int i=1; i<NN; i++) {
		for(int j=i; j<NN; j+=i) vec[j].pb(i);
	}

	scanf("%d", &n);
	build(1, 1, n+1);

	for(int i=1; i<=n; i++) {
		int u; scanf("%d", &u);
		for(int x: vec[u]) pos[x].pb(i);
	}

	for(int u=NN; --u; ) {
		if(pos[u].size()>1) {
			l=1, r=pos[u][0]+1, x=n-pos[u][pos[u].size()-2]+1;
			update(1, 1, n+1);

			l=r, r=pos[u][1]+1, x=n-pos[u].back()+1;
			update(1, 1, n+1);

			l=r, r=n+1, x=0;
			update(1, 1, n+1);
		}
		ans[u]=sum[1];
	}

	INT s=0;
	for(int i=NN-1; --i; ) {
		s+=(INT)i*(ans[i+1]-ans[i]);
	}
	printf("%I64d", s);
}


#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
#define pb push_back
#define y second
#define x first

using namespace std;
using INT=long long;
using VI=vector<int>;
using pii=pair<int, int>;

#define NN 202020

struct data {
	int L, R, g;
	data(int a=0, int b=0, int c=0) : L(a), R(b), g(c) {}
};
data vec[NN];
int a[NN], dp[NN];

int main() {
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif

	int n; scanf("%d", &n);
	for(int i=1; i<=n; i++) {
		scanf("%d", a+i);
		dp[i]=__gcd(dp[i-1], a[i]);
	}
	int N=0;
	for(int i=1, j=1; i<=n; i=j) {
		for(; j<=n && dp[i]==dp[j]; j++);
		vec[N++]={i, j-1, dp[i]};
	}

	INT ans=0;
	for(int j=n, g=0; j>=1; j--) {
		ans+=g;
		for(int i=0; i<N; i++) {
			int L=vec[i].L; if(L>=j) break;
			int R=vec[i].R; if(R>=j) R=j-1;
			int G=__gcd(vec[i].g, g);
			ans+=(INT)(R-L+1)*G;
		}
		g=__gcd(g, a[j]);
	}
	printf("%I64d", max(0LL, ans-a[1]-a[n]));
}


#include<bits/stdc++.h>
#define pb push_back

using namespace std;
using INT=long long;
using VI=vector<int>;

#define NN 200001
#define MM 524288
#define ls (u<<1)
#define rs (ls|1)
#define mid (L+R>>1)

VI vec[NN], pos[NN];
int mn[MM], mx[MM], flag[MM];
int l, r, x, n;
INT sum[MM];

void push_up(int u) {
	sum[u]=sum[ls]+sum[rs];
	mx[u]=max(mx[ls], mx[rs]);
	mn[u]=min(mn[ls], mn[rs]);
}

void build(int u, int L, int R) {
	if(R-L>1) {
		flag[u]=NN;
		build(ls, L, mid);
		build(rs, mid, R);
		push_up(u);
	}
	else {
		mn[u]=mx[u]=sum[u]=n-L+1;
	}
}

void smin(int u, int len, int x) {
	mn[u]=mx[u]=x;
	sum[u]=(INT)x*len;
	flag[u]=min(flag[u], x);
}
void push_down(int u, int L, int R) {
	if(flag[u]<NN) {
		smin(ls, mid-L, flag[u]);
		smin(rs, R-mid, flag[u]);
		flag[u]=NN;
	}
}

void update(int u, int L, int R) {
	if(mx[u]<=x) return ;
	if(r<=L || R<=l) return ;
	if(l<=L && R<=r && mn[u]>=x) {
		smin(u, R-L, x); return;
	}
	push_down(u, L, R);
	update(ls, L, mid);
	update(rs, mid, R);
	push_up(u);
}
int ans[NN];

int main() {
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif

	for(int i=1; i<NN; i++) {
		for(int j=i; j<NN; j+=i) vec[j].pb(i);
	}

	scanf("%d", &n);
	build(1, 1, n+1);

	for(int i=1; i<=n; i++) {
		int u; scanf("%d", &u);
		for(int x: vec[u]) pos[x].pb(i);
	}

	for(int u=NN; --u; ) {
		if(pos[u].size()>1) {
			l=1, r=pos[u][0]+1, x=n-pos[u][pos[u].size()-2]+1;
			update(1, 1, n+1);

			l=r, r=pos[u][1]+1, x=n-pos[u].back()+1;
			update(1, 1, n+1);

			l=r, r=n+1, x=0;
			update(1, 1, n+1);
		}
		ans[u]=sum[1];
	}

	INT s=0;
	for(int i=NN-1; --i; ) {
		s+=(INT)i*(ans[i+1]-ans[i]);
	}
	printf("%I64d", s);
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define MOD
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

int N, A[202020];
vector<int> divs[202020];
vector<pair<int, int> > eves[202020];

int main()
{
	scanf("%d", &N);
	for (int i = 0; i < N; ++i) scanf("%d", A + i);

	for (int i = 0; i < N; ++i) {
		for (int j = 1; j * j <= A[i]; ++j) {
			if (A[i] % j == 0) {
				divs[j].push_back(i);
				if (A[i] / j != j) divs[A[i] / j].push_back(i);
			}
		}
	}
	for (int i = 1; i <= 200000; ++i) if (divs[i].size() >= 2) {
		int la = divs[i][0], ra = divs[i][divs[i].size() - 2];
		int lb = divs[i][1], rb = divs[i][divs[i].size() - 1];

		eves[0].push_back({ ra, i });
		eves[la + 1].push_back({ rb, i });
		eves[lb + 1].push_back({ N, i });
	}

	set<pair<int, int> > S;
	S.insert({ N, 0 });
	const int big = 3000000;
	S.insert({ 0, big + 1});
	i64 ret = 0, tot = 0;
	for (int i = 0; i < N; ++i) {
		if (i > 0) eves[i].push_back({ i, big });
		for (auto e : eves[i]) {
		//	printf("%d: %d %d\n", i, e.first, e.second);
			int preval = S.lower_bound({ e.first, -1 })->second;
			int prepos = e.first;
			if (preval >= e.second) continue;

			S.insert({ e.first, e.second });
			for (;;) {
				auto ptr = S.lower_bound({ e.first, e.second });
				--ptr;

				ret += (i64)(e.second - preval) * (prepos - ptr->first);
				preval = ptr->second;
				prepos = ptr->first;
				if (ptr->second <= e.second) {
					S.erase(ptr);
				} else {
					break;
				}
			}
		}
		tot += ret - (i64)big * i;
	}

	cout << tot << endl;

	return 0;
}


#include<bits/stdc++.h>

#define LL long long
#define RG register

using namespace std;
template<class T> T gi() {
	T x = 0; bool f = 0; char c = getchar();
	while (c != '-' && (c < '0' || c > '9')) c = getchar();
	if (c == '-') f = 1, c = getchar();
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f ? -x : x;
}
const int N = 2e5 + 10;
vector<int> v[N], pos[N];
int mx[N << 2], mn[N << 2], tag[N << 2], a[N];
LL sum[N << 2], h[N];
#define lson (o << 1)
#define rson (o << 1 | 1)
void pushup(int o) {
	mx[o] = max(mx[lson], mx[rson]);
	mn[o] = min(mn[lson], mn[rson]);
	sum[o] = sum[lson] + sum[rson];
}
void build(int o, int l, int r) {
	if (l == r) {
		sum[o] = mx[o] = mn[o] = l;
		return ;
	}
	int mid = (l + r) >> 1;
	build(lson, l, mid); build(rson, mid + 1, r);
	pushup(o);
}
void puttag(int o, int l, int r, int x) {
	sum[o] = 1ll * (r - l + 1) * x;
	mx[o] = mn[o] = x; tag[o] = x;
}
void pushdown(int o, int l, int r) {
	if (tag[o]) {
		int mid = (l + r) >> 1;
		puttag(lson, l, mid, tag[o]);
		puttag(rson, mid + 1, r, tag[o]);
	}
}
void update(int o, int l, int r, int L, int R, int x) {
	if (mn[o] >= x) return ;
	if (L <= l && r <= R && mx[o] <= x) return puttag(o, l, r, x);
	int mid = (l + r) >> 1; pushdown(o, l, r);
	if (L <= mid) update(lson, l, mid, L, R, x);
	if (R > mid) update(rson, mid + 1, r, L, R, x);
	pushup(o);
}
int main() {
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	int n = gi<int>(), mx = 0;
	for (int i = 1; i < N; i++)
		for (int j = i; j < N; j += i)
			v[j].push_back(i);
	for (int i = 1; i <= n; i++) {
		a[i] = gi<int>(); mx = max(mx, a[i]);
		for (auto j : v[a[i]])
			pos[j].push_back(i);
	}
	build(1, 1, n);
	for (int i = mx; i >= 0; i--) {
		h[i] = 1ll * n * (n + 1) - sum[1];
		if (pos[i].size() < 2) continue;
		update(1, 1, n, pos[i][1] + 1, n, n + 1);
		update(1, 1, n, pos[i][0] + 1, pos[i][1], *pos[i].rbegin());
		update(1, 1, n, 1, pos[i][0], pos[i][pos[i].size() - 2]);
	}
	LL ans = 0;
	for (int i = mx; i; i--) {
		//	printf("%lld\n", h[i] - h[i - 1]);
		ans += (h[i] - h[i - 1]) * i;
	}
	cout << ans << endl;
	return 0;
}


#include<bits/stdc++.h>

#define LL long long
#define RG register

using namespace std;
template<class T> T gi() {
	T x = 0; bool f = 0; char c = getchar();
	while (c != '-' && (c < '0' || c > '9')) c = getchar();
	if (c == '-') f = 1, c = getchar();
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f ? -x : x;
}
const int N = 2e5 + 10;
vector<int> v[N], pos[N];
int mx[N << 2], mn[N << 2], tag[N << 2], a[N];
LL sum[N << 2], h[N];
#define lson (o << 1)
#define rson (o << 1 | 1)
void pushup(int o) {
	mx[o] = max(mx[lson], mx[rson]);
	mn[o] = min(mn[lson], mn[rson]);
	sum[o] = sum[lson] + sum[rson];
}
void build(int o, int l, int r) {
	if (l == r) {
		sum[o] = mx[o] = mn[o] = l;
		return ;
	}
	int mid = (l + r) >> 1;
	build(lson, l, mid); build(rson, mid + 1, r);
	pushup(o);
}
void puttag(int o, int l, int r, int x) {
	sum[o] = 1ll * (r - l + 1) * x;
	mx[o] = mn[o] = x; tag[o] = x;
}
void pushdown(int o, int l, int r) {
	if (tag[o]) {
		int mid = (l + r) >> 1;
		puttag(lson, l, mid, tag[o]);
		puttag(rson, mid + 1, r, tag[o]);
		tag[o] = 0;
	}
}
void update(int o, int l, int r, int L, int R, int x) {
	if (mn[o] >= x) return ;
	if (L <= l && r <= R && mx[o] <= x) return puttag(o, l, r, x);
	int mid = (l + r) >> 1; pushdown(o, l, r);
	if (L <= mid) update(lson, l, mid, L, R, x);
	if (R > mid) update(rson, mid + 1, r, L, R, x);
	pushup(o);
}
int main() {
	freopen("in.in", "r", stdin);
	//freopen(".out", "w", stdout);
	int n = gi<int>(), mx = 0;
	for (int i = 1; i < N; i++)
		for (int j = i; j < N; j += i)
			v[j].push_back(i);
	for (int i = 1; i <= n; i++) {
		a[i] = gi<int>(); mx = max(mx, a[i]);
		for (auto j : v[a[i]])
			pos[j].push_back(i);
	}
	build(1, 1, n);
	for (int i = mx; i >= 0; i--) {
		h[i] = 1ll * n * (n + 1) - sum[1];
		if (pos[i].size() < 2) continue;
		update(1, 1, n, pos[i][1] + 1, n, n + 1);
		update(1, 1, n, pos[i][0] + 1, pos[i][1], *pos[i].rbegin());
		update(1, 1, n, 1, pos[i][0], pos[i][pos[i].size() - 2]);
	}
	LL ans = 0;
	for (int i = mx; i; i--) {
		//	printf("%lld\n", h[i] - h[i - 1]);
		ans += (h[i] - h[i - 1]) * i;
	}
	cout << ans << endl;
	return 0;
}


#include<bits/stdc++.h>

#define LL long long
#define RG register

using namespace std;
template<class T> T gi() {
	T x = 0; bool f = 0; char c = getchar();
	while (c != '-' && (c < '0' || c > '9')) c = getchar();
	if (c == '-') f = 1, c = getchar();
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f ? -x : x;
}
const int N = 2e5 + 10;
vector<int> v[N], pos[N];
int mx[N << 2], mn[N << 2], tag[N << 2], a[N];
LL sum[N << 2], h[N];
#define lson (o << 1)
#define rson (o << 1 | 1)
void pushup(int o) {
	mx[o] = max(mx[lson], mx[rson]);
	mn[o] = min(mn[lson], mn[rson]);
	sum[o] = sum[lson] + sum[rson];
}
void build(int o, int l, int r) {
	if (l == r) {
		sum[o] = mx[o] = mn[o] = l;
		return ;
	}
	int mid = (l + r) >> 1;
	build(lson, l, mid); build(rson, mid + 1, r);
	pushup(o);
}
void puttag(int o, int l, int r, int x) {
	sum[o] = 1ll * (r - l + 1) * x;
	mx[o] = mn[o] = x; tag[o] = x;
}
void pushdown(int o, int l, int r) {
	if (tag[o]) {
		int mid = (l + r) >> 1;
		puttag(lson, l, mid, tag[o]);
		puttag(rson, mid + 1, r, tag[o]);
		tag[o] = 0;
	}
}
void update(int o, int l, int r, int L, int R, int x) {
	if (mn[o] >= x) return ;
	if (L <= l && r <= R && mx[o] <= x) return puttag(o, l, r, x);
	int mid = (l + r) >> 1; pushdown(o, l, r);
	if (L <= mid) update(lson, l, mid, L, R, x);
	if (R > mid) update(rson, mid + 1, r, L, R, x);
	pushup(o);
}
int main() {
	int n = gi<int>(), mx = 0;
	for (int i = 1; i < N; i++)
		for (int j = i; j < N; j += i)
			v[j].push_back(i);
	for (int i = 1; i <= n; i++) {
		a[i] = gi<int>(); mx = max(mx, a[i]);
		for (auto j : v[a[i]])
			pos[j].push_back(i);
	}
	build(1, 1, n);
	for (int i = mx; i >= 0; i--) {
		h[i] = 1ll * n * (n + 1) - sum[1];
		if (pos[i].size() < 2) continue;
		update(1, 1, n, pos[i][1] + 1, n, n + 1);
		update(1, 1, n, pos[i][0] + 1, pos[i][1], *pos[i].rbegin());
		update(1, 1, n, 1, pos[i][0], pos[i][pos[i].size() - 2]);
	}
	LL ans = 0;
	for (int i = mx; i; i--) {
		//	printf("%lld\n", h[i] - h[i - 1]);
		ans += (h[i] - h[i - 1]) * i;
	}
	cout << ans << endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std ;
const int maxn = 2e5 +10 ;
const int maxL = 20 ;
#define fast ios_base::sync_with_stdio(false),cin.tie(),cout.tie()
#define X first
#define Y second
#define int long long
typedef long double ld ;
typedef pair < int , int > pii ;
typedef pair < pii , int > pii_i ;
typedef pair < int , pii > pi_ii ;
typedef pair < pii , pii > pii_ii ;
typedef long double ld ;
const int mod = 1e9+7 ;
const ld inf = 1e12 ;
#define ALL(x) (x).begin(),(x).end()
#define time edskhfghdfjkldhljkgdhfkl
#define size(x) ((long)(x).size())
const int baze = 333 ;
int flag [ 4 * maxn ] ;
int sum_data [ 4 * maxn ] ;
int min_data [ 4 * maxn ] ;
int n , ar [ maxn ] , where [ maxn ] ;

void build ( int st = 0 , int en = n , int id = 1 )
{
  if ( en - st < 2 )
    {
      min_data [ id ] = st ;
      sum_data [ id ] = st ;
      return ;
    }
  int mid = ( st + en ) >> 1 ;
  build ( st , mid , id << 1 ) ;
  build ( mid , en , id << 1 ^ 1 ) ;
  min_data [ id ] = min ( min_data [ id << 1 ] , min_data [ id << 1 ^ 1 ] ) ;
  sum_data [ id ] = sum_data [ id << 1 ] + sum_data [ id << 1 ^ 1 ] ;
}

void relax_flag ( const int &st , const int &en , const int &id )
{
  if ( flag [ id ] == -1 )
    return ;
  sum_data [ id ] = (en-st)* flag [ id ] ;
  min_data [ id ] = flag [ id ] ;
  if ( en - st > 1 )
    {
      flag [ id << 1 ] = flag [ id ] ;
      flag [ id << 1 ^ 1 ] = flag [ id ] ;
    }
  flag [ id ] = -1 ;
}

void add ( int l , int r , int x , int st = 0 , int en = n , int id = 1 )
{
  relax_flag ( st , en , id ) ;
  if ( l <= st && en <= r )
    {
      flag [ id ] = x ;
      relax_flag ( st , en , id ) ;
      return ;
    }
  if ( r <= st || en <= l )
  return ;
  int mid = (st+en)>>1 ;
  add ( l , r , x , st , mid , id << 1 ) ;
  add ( l , r , x , mid , en , id << 1 ^ 1 ) ;
  min_data [ id ] = min ( min_data [ id << 1 ] , min_data [ id << 1 ^ 1 ] ) ;
  sum_data [ id ] = sum_data [ id << 1 ] + sum_data [ id << 1 ^ 1 ] ;
}

int get ( int l , int r , int x , int st = 0 , int en = n , int id = 1 )
{
  relax_flag ( st , en , id ) ;
  if ( l <= st && en <= r )
    {
      if ( min_data [ id ] >= x )
	return -1 ;
      else if ( en - st < 2 )
	return en ;
    }
  if ( r <= st || en <= l )
    return -1 ;
  int mid = (st+en)>>1 ;
  int ret = get ( l , r , x , mid , en , id << 1 ^ 1 ) ;
  if ( ret != -1 )
    return ret ;
  return get ( l , r , x , st , mid , id << 1 ) ;
}

void helper ( int s , int e )
{
  return add ( s , get ( s , e , e ) , e ) ;
}

int32_t main ( )
{
  fast ;
  int ans = 0 ;
  for ( int i = 0 ; i < 4*maxn ; i ++)
    flag [ i ] = -1 ;
  cin >> n ;
  for ( int i = 0 ; i < maxn ; i ++ )
    where [ i ] = -1 ;
  for ( int i = 0 ; i < n ; i ++ )
    cin >> ar [ i ] , where [ ar [ i ] ] = i ;
  build ( ) ;
  for ( int i = maxn - 1 ; i > 0 ; i -- )
    {
      vector < int > vc ;
      for ( int j = i ; j < maxn ; j += i )
	if ( where [ j ] != -1 )
	  vc . push_back ( where [ j ] ) ;
      sort ( ALL ( vc ) ) ;
      if ( size ( vc ) > 1 )
	{
	  helper ( 0 , vc [ size ( vc ) - 2 ] ) ;
	  helper ( vc [ 1 ]+1 , n ) ;
	  helper ( vc [ 0 ] + 1 , vc .back() ) ;
	}
      relax_flag ( 0 , n , 1 ) ;
      ans += sum_data [ 1 ] - ((n*(n-1))>>1) ;
    }
  cout << ans << endl ;
}
//g++ -std=c++14 -O2 -Wall -Wextra a.cpp


#include<cstdio>
#include<algorithm>
using namespace std;
int gi(){
	int x=0,w=1;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	if(ch=='-')w=0,ch=getchar();
	while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
	return w?x:-x;
}
#define ll long long
const int N=5e5+5;
int n,m,a[N],pos[N],mx[N<<2],mn[N<<2],tag[N<<2];
ll sum[N<<2],h[N],ans;vector<int>v[N];
void up(int x){
	sum[x]=sum[x<<1]+sum[x<<1|1];
	mn[x]=mn[x<<1];mx[x]=mx[x<<1|1];
}
void build(int x,int l,int r){
	if(l==r){sum[x]=mx[x]=mn[x]=l;return;}
	int mid=l+r>>1;build(x<<1,l,mid);build(x<<1|1,mid+1,r);up(x);
}
void cover(int x,int l,int r,int v){
	sum[x]=1ll*(r-l+1)*v;mn[x]=mx[x]=v;tag[x]=v;
}
void down(int x,int l,int mid,int r){
	if(!tag[x])return;
	cover(x<<1,l,mid,tag[x]);cover(x<<1|1,mid+1,r,tag[x]);tag[x]=0;
}
void modify(int x,int l,int r,int ql,int qr,int v){
	if(mn[x]>=v)return;if(l>=ql&&r<=qr&&mx[x]<=v){cover(x,l,r,v);return;}
	int mid=l+r>>1;down(x,l,mid,r);
	if(ql<=mid)modify(x<<1,l,mid,ql,qr,v);
	if(qr>mid)modify(x<<1|1,mid+1,r,ql,qr,v);
	up(x);
}
int main(){
//	freopen("gcd.in","r",stdin);
//	freopen("gcd.out","w",stdout);
	n=gi();
	for(int i=1;i<=n;++i)m=max(m,a[i]=gi()),pos[a[i]]=i;
	for(int i=1;i<=m;++i){
		for(int j=i;j<=m;j+=i)
			if(pos[j])v[i].push_back(pos[j]);
		sort(v[i].begin(),v[i].end());
	}
	build(1,1,n);
	for(int i=m;~i;--i){
		h[i]=1ll*n*(n+1)-sum[1];
		int sz=v[i].size();if(sz<=1)continue;
		modify(1,1,n,1,v[i][0],v[i][sz-2]);
		modify(1,1,n,v[i][0]+1,v[i][1],v[i][sz-1]);
		if(v[i][1]<n)modify(1,1,n,v[i][1]+1,n,n+1);
	}
	for(int i=1;i<=m;++i)ans+=(h[i]-h[i-1])*i;
	printf("%lld\n",ans);return 0;
}


#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
int gi(){
	int x=0,w=1;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	if(ch=='-')w=0,ch=getchar();
	while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
	return w?x:-x;
}
#define ll long long
const int N=5e5+5;
int n,m,mx[N<<2],mn[N<<2],tag[N<<2];
ll sum[N<<2],h[N],ans;
vector<int>pos[N],vec[N];
void up(int x){
	sum[x]=sum[x<<1]+sum[x<<1|1];
	mn[x]=mn[x<<1];mx[x]=mx[x<<1|1];
}
void build(int x,int l,int r){
	if(l==r){sum[x]=mn[x]=l;return;}
	int mid=l+r>>1;build(x<<1,l,mid);build(x<<1|1,mid+1,r);up(x);
}
void cover(int x,int l,int r,int v){
	sum[x]=1ll*(r-l+1)*v;mn[x]=mx[x]=tag[x]=v;
}
void down(int x,int l,int mid,int r){
	if(!tag[x])return;
	cover(x<<1,l,mid,tag[x]);cover(x<<1|1,mid+1,r,tag[x]);tag[x]=0;
}
void modify(int x,int l,int r,int ql,int qr,int v){
	if(mn[x]>=v)return;
	if(l>=ql&&r<=qr&&mx[x]<=v){cover(x,l,r,v);return;}
	int mid=l+r>>1;down(x,l,mid,r);
	if(ql<=mid)modify(x<<1,l,mid,ql,qr,v);
	if(qr>mid)modify(x<<1|1,mid+1,r,ql,qr,v);
	up(x);
}
int main(){
//	freopen("gcd.in","r",stdin);
//	freopen("gcd.out","w",stdout);
	n=gi();
	for(int i=1,x;i<=n;++i)m=max(m,x=gi()),pos[x].push_back(i);
	for(int i=1;i<=m;++i){
		for(int j=i;j<=m;j+=i){
			int sz=pos[j].size();
			if(sz<=4)for(int k:pos[j])vec[i].push_back(k);
			else{
				vec[i].push_back(pos[j][0]),vec[i].push_back(pos[j][1]);
				vec[i].push_back(pos[j][sz-2]),vec[i].push_back(pos[j][sz-1]);
			}
		}
		sort(vec[i].begin(),vec[i].end());
	}
	build(1,1,n);
	for(int i=m;~i;--i){
		h[i]=1ll*n*(n+1)-sum[1];
		int sz=vec[i].size();if(sz<=1)continue;
		modify(1,1,n,1,vec[i][0],vec[i][sz-2]);
		modify(1,1,n,vec[i][0]+1,vec[i][1],vec[i][sz-1]);
		if(vec[i][1]<n)modify(1,1,n,vec[i][1]+1,n,n+1);
	}
	for(int i=1;i<=m;++i)ans+=(h[i]-h[i-1])*i;
	printf("%lld\n",ans);return 0;
}


#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
int gi(){
	int x=0,w=1;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	if(ch=='-')w=0,ch=getchar();
	while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
	return w?x:-x;
}
#define ll long long
const int N=5e5+5;
int n,m,a[N],pos[N],mx[N<<2],mn[N<<2],tag[N<<2];
ll sum[N<<2],h[N],ans;vector<int>v[N];
void up(int x){
	sum[x]=sum[x<<1]+sum[x<<1|1];
	mn[x]=mn[x<<1];mx[x]=mx[x<<1|1];
}
void build(int x,int l,int r){
	if(l==r){sum[x]=mx[x]=mn[x]=l;return;}
	int mid=l+r>>1;build(x<<1,l,mid);build(x<<1|1,mid+1,r);up(x);
}
void cover(int x,int l,int r,int v){
	sum[x]=1ll*(r-l+1)*v;mn[x]=mx[x]=v;tag[x]=v;
}
void down(int x,int l,int mid,int r){
	if(!tag[x])return;
	cover(x<<1,l,mid,tag[x]);cover(x<<1|1,mid+1,r,tag[x]);tag[x]=0;
}
void modify(int x,int l,int r,int ql,int qr,int v){
	if(mn[x]>=v)return;if(l>=ql&&r<=qr&&mx[x]<=v){cover(x,l,r,v);return;}
	int mid=l+r>>1;down(x,l,mid,r);
	if(ql<=mid)modify(x<<1,l,mid,ql,qr,v);
	if(qr>mid)modify(x<<1|1,mid+1,r,ql,qr,v);
	up(x);
}
int main(){
//	freopen("gcd.in","r",stdin);
//	freopen("gcd.out","w",stdout);
	n=gi();
	for(int i=1;i<=n;++i)m=max(m,a[i]=gi()),pos[a[i]]=i;
	for(int i=1;i<=m;++i){
		for(int j=i;j<=m;j+=i)
			if(pos[j])v[i].push_back(pos[j]);
		sort(v[i].begin(),v[i].end());
	}
	build(1,1,n);
	for(int i=m;~i;--i){
		h[i]=1ll*n*(n+1)-sum[1];
		int sz=v[i].size();if(sz<=1)continue;
		modify(1,1,n,1,v[i][0],v[i][sz-2]);
		modify(1,1,n,v[i][0]+1,v[i][1],v[i][sz-1]);
		if(v[i][1]<n)modify(1,1,n,v[i][1]+1,n,n+1);
	}
	for(int i=1;i<=m;++i)ans+=(h[i]-h[i-1])*i;
	printf("%lld\n",ans);return 0;
}