#include <bits/stdc++.h>
using namespace std;

#define foreach(i,x) for(type(x)i=x.begin();i!=x.end();i++)
#define FOR(ii,aa,bb) for(int ii=aa;ii<=bb;ii++)
#define ROF(ii,aa,bb) for(int ii=aa;ii>=bb;ii--)

#define type(x) __typeof(x.begin())
#define pb push_back
#define mp make_pair
#define nd second
#define st first
typedef pair < int ,int > pii;
typedef long long ll;
const long long linf = 1e18+5;
int mod = (int) 1e9 + 7;
const int logN = 18;
const int inf = 1e9;
const int N = 2e5 + 5;

int n, m, x, y, z, a[N];
vector< int > H[N], v[N];
ll sum = 0, ans[N];
set<pair<pii, int> > S;
set<pair<pii, int> > :: iterator it, it2;
void divide(int x) {
    //let 1...x be an isolate part
    it = S.lower_bound(mp(mp(x + 1, 0), -1));
    if(it == S.begin()) return ; it--;
    if(it->st.nd < x) return ;
    pair<pii, int > t = *it; S.erase(*it);
    S.insert(mp(mp(t.st.st, x), t.nd));
    if(x + 1 <= t.st.nd) S.insert(mp(mp(x + 1, t.st.nd), t.nd));
}

void remove(int x) {
    //remove all elements with idx >= x
    //let 1...x - 1 be an isolate part
    divide(x - 1);
    while(S.rbegin()->st.st >= x) {
        pair<pii, int> t = *S.rbegin();
        sum -= (t.st.nd - t.st.st + 1) * (ll) (t.nd);
        S.erase(t);
    }
}

void maximize(set<pair<pii, int> > :: iterator it, int x, int y) {
    pair<pii, int> t; t.nd = x; t.st.st = y;
    while(it != S.end()) {
        if(it->nd >= x) break;
        t.st.nd = it->st.nd;
        sum -= (it->st.nd - it->st.st + 1) * (ll) (it->nd);
        it2 = it; it2++; S.erase(it); it = it2;
    }
    if(t.st.st <= t.st.nd) {
        sum += (t.st.nd - t.st.st + 1) * (ll) t.nd;
        S.insert(t);
    }
}

int main() {
    //freopen("in.txt", "r", stdin);
    scanf("%d", &n);
    FOR(i, 1, n) {
        scanf("%d", &a[i]);
        H[a[i]].pb(i); sum += i;
        S.insert(mp(mp(i, i), i));
    }
    FOR(i, 1, N - 1) for(int j = i; j < N; j += i) foreach(it, H[j]) v[i].pb(*it);
    ans[N - 1] = n * (ll) (n + 1) / 2;
    ROF(i, N - 2, 1) {
        int l = v[i].size() - 1;
        if(l <= 0) { ans[i] = ans[i + 1]; continue; }
        sort(v[i].begin(), v[i].end());
        remove(v[i][1] + 1);
        maximize(S.begin(), v[i][l-1], 1);
        divide(v[i][0]);
        maximize(S.lower_bound(mp(mp(v[i][0] + 1, v[i][0]), 0)), v[i][l], v[i][0] + 1);
        ans[i] = (S.rbegin()->st.nd * (ll)(n + 1) - sum);
    }
    ll all = 0;
    FOR(i, 1, N - 2) all += (ans[i + 1] - ans[i]) * (ll) i;
    printf("%lld\n", all);

    return 0;
}


#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
const int N=200005,M=200000;
typedef long long ll;
int a[N],n,m,l1[N],r1[N],l2[N],r2[N];
ll f[N],ans;
struct node{
	int mx,mi;
	ll sum,tag;
}tr[N*4];
inline void updata(int x){
	tr[x].mx=max(tr[x<<1].mx,tr[x<<1|1].mx);
	tr[x].mi=min(tr[x<<1].mi,tr[x<<1|1].mi);
	tr[x].sum=tr[x<<1].sum+tr[x<<1|1].sum;
}
void build(int x,int l,int r){
	if (l==r){
		tr[x].mx=tr[x].mi=tr[x].sum=l;
		return;
	}
	int mid=(l+r)>>1;
	build(x<<1,l,mid);
	build(x<<1|1,mid+1,r);
	updata(x);
}
inline  void work(int x,int l,int r,ll m){
	tr[x].mx=tr[x].mi=m;
	tr[x].sum=m*(r-l+1);
	tr[x].tag=m;
}
void pushdown(int x,int l,int r){
	if (tr[x].tag){
		if (l==r) return;
		work(x<<1,l,(l+r)>>1,tr[x].tag);
		work(x<<1|1,((l+r)>>1)+1,r,tr[x].tag);
		tr[x].tag=0;
	}
}
void modify(int x,int l,int r,int s,int t,ll m){
	pushdown(x,l,r);
	if (tr[x].mi>=m) return;
	if (l==s && r==t && m>tr[x].mx){
		work(x,l,r,m);
		return;
	}
	int mid=(l+r)>>1;
	if (t<=mid) modify(x<<1,l,mid,s,t,m);
	else if (s>mid) modify(x<<1|1,mid+1,r,s,t,m);
	else {
		modify(x<<1,l,mid,s,mid,m);
		modify(x<<1|1,mid+1,r,mid+1,t,m);
	}
	updata(x);
}
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	for (int i=1;i<=n;i++){
		int m=sqrt(a[i]);
		for (int j=1;j<=m;j++){
			 if (a[i]%j==0) {
		 		if (!l1[j]) l1[j]=i;
		 		else if (!l2[j]) l2[j]=i;
		 		r2[j]=r1[j],r1[j]=i;
		 		if (a[i]!=j*j){
		 		if (!l1[a[i]/j]) l1[a[i]/j]=i;
		 		else if (!l2[a[i]/j]) l2[a[i]/j]=i;
		 		r2[a[i]/j]=r1[a[i]/j],r1[a[i]/j]=i;
			 }
		 	}
		}

	}
	build(1,1,n);
	f[M+1]=(ll)n*(n+1)/2;
	for (int i=M;i>=0;i--){
		f[i]=f[i+1];
		if (l1[i]==r1[i]) continue;
		modify(1,1,n,1,l1[i],r2[i]);
		modify(1,1,n,l1[i]+1,l2[i],r1[i]);
		if (l2[i]+1<=n)
		modify(1,1,n,l2[i]+1,n,n+1);
		f[i]=(ll)n*(n+1)-tr[1].sum;
	}
	for (int i=1;i<=M;i++)
	 ans+=(f[i+1]-f[i])*i;
	 printf("%I64d",ans);
	return 0;
}


//#define NDEBUG
#include <bits/stdc++.h>

using namespace std ;

//----------------------------------------------------------------------------------------------------------------------------------------------

typedef long long int lli ;
typedef long double ld ;
typedef pair < int , int > pii ;
typedef pair < lli , lli > pllilli ;

typedef vector < int > vi ;
typedef vector < lli > vlli ;
typedef vector < bool > vb ;
typedef vector < string > vs ;
typedef vector < float > vf ;
typedef vector < double > vd ;
typedef vector < ld > vld ;
typedef vector < pii > vpii ;
typedef vector < pllilli > vpllilli ;

typedef vector < vi > vvi ;
typedef vector < vvi > vvvi ;
typedef vector < vvvi > vvvvi ;
typedef vector < vlli > vvlli ;
typedef vector < vvlli > vvvlli ;
typedef vector < vvvlli > vvvvlli ;
typedef vector < vb > vvb ;
typedef vector < vs > vvs ;
typedef vector < vf > vvf ;
typedef vector < vd > vvd ;
typedef vector < vld > vvld ;
typedef vector < vpii > vvpii ;
typedef vector < vpllilli > vvpllilli ;

typedef set < int > si ;
typedef set < lli > slli ;
typedef set < pii > spii ;
typedef set < pllilli > spllilli ;
typedef set < string > ss ;

typedef unordered_set < int > usi ;
typedef unordered_set < lli > uslli ;
typedef unordered_set < pii > uspii ;
typedef unordered_set < pllilli > uspllilli ;
typedef unordered_set < string > uss ;

typedef map < int , int > mii ;
typedef map < lli , lli > mllilli ;
typedef map < int , pii > mipii ;
typedef map < pii , pii > mpiipii ;
typedef map < pii , int > mpiii ;
typedef map < int , string > mis ;
typedef map < string , int > msi ;
typedef map < string , string > mss ;

typedef unordered_map < int , int > umii ;
typedef unordered_map < lli , lli > umllilli ;
typedef unordered_map < int , pii > umipii ;
typedef unordered_map < pii , pii > umpiipii ;
typedef unordered_map < pii , int > umpiii ;
typedef unordered_map < int , string > umis ;
typedef unordered_map < string , int > umsi ;
typedef unordered_map < string , string > umss ;

#define dash "---------------------------------------------------"
#define fie(i,start,stop) for ( int i = start ; i < stop ; i ++ )
#define fii(i,start,stop) for ( int i = start ; i <= stop ; i ++ )
#define fdei(i,start,stop) for ( int i = start - 1 ; i >= stop ; i -- )
#define fdii(i,start,stop) for ( int i = start ; i >= stop ; i -- )
#define tr(it,container) for ( __typeof ( container.begin () ) it = container.begin () ; it != container.end () ; it ++ )
#define print(s,x) cout << "> " << s << " " << #x << " : " << x << endl
#define print1(x) cout << "> " << #x << " : " << x << endl
#define print2(x1,x2) cout << "> " << #x1 << " : " << x1 << " , " << #x2 << " : " << x2 << endl
#define print3(x1,x2,x3) cout << "> " << #x1 << " : " << x1 << " , " << #x2 << " : " << x2 << " , " << #x3 << " : " << x3 << endl
#define print4(x1,x2,x3,x4) cout << "> " << #x1 << " : " << x1 << " , " << #x2 << " : " << x2 << " , " << #x3 << " : " << x3 << " , " << #x4 << " : " << x4 << endl
#define all(x) x.begin () , x.end ()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define error 0.00000001
#define lb lower_bound
#define ub upper_bound

template < class T > void print_2darray ( const char * s , T arr , int n , int m )
{
    cout << "> " << s << endl ;
    cout << "[" << endl ;
    fie ( i , 0 , n )
    {
        cout << "{" ;
        fie ( j , 0 , m )
        {
            cout << arr [ i ] [ j ] << ( j == m - 1 ? "" : "," ) ;
        }
        cout << "}" << endl ;
    }
    cout << "]" << endl ;
}

template < class T > void print_2darray ( const char * s , T arr , int n )
{
    cout << "> " << s << endl ;
    cout << "[" << endl ;
    fie ( i , 0 , n )
    {
        cout << i << " - {" ;
        fie ( j , 0 , ( int ) arr [ i ].size () )
        {
            cout << arr [ i ] [ j ] << ( j == ( int ) arr [ i ].size () - 1 ? "" : "," ) ;
        }
        cout << "}" << endl ;
    }
    cout << "]" << endl ;
}

template < class T > void print_1darray ( const char * s , T arr , int n )
{
    cout << "> " << s << endl ;
    cout << "[" << endl ;
    fie ( i , 0 , n )
    {
        cout << arr [ i ] << ( i == n - 1 ? "" : "," ) ;
    }
    cout << endl << "]" << endl ;
}

template < class T > void print_1darray ( const char * s , T arr )
{
    cout << "> " << s << endl ;
    cout << "[" << endl ;
    fie ( i , 0 , arr.size () )
    {
        cout << arr [ i ] << ( i == ( int ) arr.size () - 1 ? "" : "," ) ;
    }
    cout << endl << "]" << endl ;
}

template < class T > void print_set ( const char * s , set < T > & myset )
{
    cout << "> " << s << endl ;
    cout << "[" << endl ;
    tr ( it , myset )
    {
        cout << * it << " " ;
    }
    cout << endl << "]" << endl ;
}

template < class T > void print_uset ( const char * s , unordered_set < T > & myset )
{
    cout << "> " << s << endl ;
    cout << "[" << endl ;
    tr ( it , myset )
    {
        cout << * it << " " ;
    }
    cout << endl << "]" << endl ;
}

template < class T1 , class T2 > void print_map ( const char * s , map < T1 , T2 > & mymap )
{
    cout << "> " << s << endl ;
    cout << "[" << endl ;
    tr ( it , mymap )
    {
        cout << "{" << it->f << "->" << it->s << "}" << endl ;
    }
    cout << "]" << endl ;
}

template < class T1 , class T2 > void print_umap ( const char * s , unordered_map < T1 , T2 > & mymap )
{
    cout << "> " << s << endl ;
    cout << "[" << endl ;
    tr ( it , mymap )
    {
        cout << "{" << it->f << "->" << it->s << "}" << endl ;
    }
    cout << "]" << endl ;
}

//----------------------------------------------------------------------------------------------------------------------------------------------

//#define dbg 1

const int N = 200000 ;
int n , x ;
vi a ( N + 1 , -1 ) ;
vi v [ N + 1 ] ;
lli ans [ N + 1 ] ;
lli all_ans = 0 ;

struct segment_tree
{
    // st.set_vars ( n , 0 , arr ) ;
    // st.construct ( ) ;
    // st.get_sum ( 1 , 3 )
    // st.update_range ( 1 , 5 , 10 ) ; // add 10 to all nodes so difference = 10

    #define seg_size 1 << 19
    int n , init ;
    int * arr ;
    lli tree [ seg_size ] ;
    lli lazy [ seg_size ] ;
    int small [ seg_size ] ;
    int big [ seg_size ] ;

    void set_vars ( int _n , int _init , int * _arr = NULL )
    {
        n = _n ;
        init = _init ;
        arr = _arr ;
        //fill_n ( & small [ 0 ] , seg_size , 0 ) ;
        //fill_n ( & big [ 0 ] , seg_size , 0 ) ;
        if ( init != 0 )
        {
            fill_n ( & tree [ 0 ] , seg_size , init ) ;
            fill_n ( & lazy [ 0 ] , seg_size , init ) ;
        }
    }

    void updaterange_util ( int si , int ss , int se , int us , int ue , lli diff )
    {
        if ( lazy [ si ] != init )
        {
            small [ si ] = big [ si ] = lazy [ si ] ;
            tree [ si ] = ( se - ss + 1 ) * lazy [ si ] ;
            if ( ss != se )
            {
                lazy [ si * 2 + 1 ] = lazy [ si ] ;
                lazy [ si * 2 + 2 ] = lazy [ si ] ;
            }
            lazy [ si ] = init ;
        }
        if ( ss > se || ss > ue || se < us || small [ si ] >= diff )
        {
            return ;
        }
        if ( ss >= us && se <= ue && big [ si ] <= diff )
        {
            tree [ si ] = ( se - ss + 1 ) * diff ;
            small [ si ] = big [ si ] = diff ;
            if ( ss != se )
            {
                lazy [ si * 2 + 1 ] = diff ;
                lazy [ si * 2 + 2 ] = diff ;
            }
            return ;
        }
        int mid = ( ss + se ) / 2 ;
        updaterange_util ( si * 2 + 1 , ss , mid , us , ue , diff ) ;
        updaterange_util ( si * 2 + 2 , mid + 1 , se , us , ue , diff ) ;
        small [ si ] = min ( small [ si * 2 + 1 ] , small [ si * 2 + 2 ] ) ;
        big [ si ] = max ( big [ si * 2 + 1 ] , big [ si * 2 + 2 ] ) ;
        tree [ si ] = tree [ si * 2 + 1 ] + tree [ si * 2 + 2 ] ;
    }

    void update_range ( int us , int ue , lli diff )
    {
       updaterange_util ( 0 , 0 , n - 1 , us , ue , diff ) ;
    }
} st ;

int main ()
{
    cin >> n ;
    if ( n <= 2 )
    {
        cout << 0 ;
        return 0 ;
    }
    fie ( i , 0 , n )
    {
        cin >> x ;
        a [ x ] = i ;
    }
    fii ( i , 1 , N )
    {
        for ( int j = i ; j <= N ; j += i )
        {
            if ( a [ j ] != -1 )
            {
                v [ i ].pb ( a [ j ] ) ;
            }
        }
        sort ( all ( v [ i ] ) ) ;
    }
    st.set_vars ( n , 0 ) ;
    fii ( i , 0 , N )
    {
        st.update_range ( i , i , i ) ;
    }
    ans [ N ] = ( ( lli ) n * ( lli ) ( n + 1 ) ) / 2LL ;
    ans [ 0 ] = 3 ;
    fdei ( i , N , 1 )
    {
        int len = v [ i ].size () ;
        if ( len <= 1 )
        {
            ans [ i ] = -1 ;
            #ifdef dbg
            if ( i <= 7 )
            {
                print ( i , ans [ i ] ) ;
            }
            #endif
            continue ;
        }
        ans [ i ] = ( lli ) n * ( lli ) ( n ) - st.tree [ 0 ] ;
        #ifdef dbg
            print ( i , ans [ i ] ) ;
            cout << i << " val @ root = " << st.tree [ 0 ] << endl ;
        #endif
        st.update_range ( 0 , v [ i ] [ 0 ] , v [ i ] [ len - 2 ] ) ;
        st.update_range ( v [ i ] [ 0 ] + 1 , v [ i ] [ 1 ] , v [ i ] [ len - 1 ] ) ;
        st.update_range ( v [ i ] [ 1 ] + 1 , n - 1 , n ) ;
    }
    fdii ( i , N , 1 )
    {
        int cur = i - 1 ;
        while ( ans [ cur ] == -1 )
        {
            cur -- ;
        }
        all_ans += ( ans [ i ] - ans [ cur ] ) * ( lli ) i ;
        i = cur ;
        i ++ ;
    }
    cout << all_ans ;

    return 0 ;
}


#include<set>
#include<map>
#include<list>
#include<cmath>
#include<queue>
#include<ctime>
#include<stack>
#include<bitset>
#include<string>
#include<vector>
#include<cstdio>
#include<climits>
#include<cstring>
#include<iomanip>
#include<iostream>
#include<algorithm>
using namespace std;

const int maxn=200010;
vector <int> v[maxn];
long long h[maxn];
int n;

struct nodetree
{
    int l,r;
    long long x,y;
    long long lazy;
    long long sum;
}a[maxn<<2];

void push_up(int i)
{
    a[i].x=min(a[2*i].x,a[2*i+1].x);
    a[i].y=max(a[2*i].y,a[2*i+1].y);
    a[i].sum=a[2*i].sum+a[2*i+1].sum;
}

void push_down(int i)
{
    if(a[i].l!=a[i].r&&a[i].lazy!=-1)
    {
        a[2*i].x=a[2*i].y=a[i].lazy;
        a[2*i].sum=a[i].lazy*(a[2*i].r-a[2*i].l+1);
        a[2*i].lazy=a[i].lazy;

        a[2*i+1].x=a[2*i+1].y=a[i].lazy;
        a[2*i+1].sum=a[i].lazy*(a[2*i+1].r-a[2*i+1].l+1);
        a[2*i+1].lazy=a[i].lazy;

        a[i].lazy=-1;
    }
}

void init(int i,int l,int r)
{
    a[i].l=l;
    a[i].r=r;
    a[i].lazy=-1;
    if(l==r)
    {
        a[i].x=l;
        a[i].y=l;
        a[i].sum=l;
        return;
    }
    int mid=(l+r)/2;
    init(2*i,l,mid);
    init(2*i+1,mid+1,r);
    push_up(i);
}

long long find(int i,int num)
{
    push_down(i);
    if(a[i].y<=num)
        return a[i].r;
    if(a[i].x>=num)
        return -1;

    int tmp=find(2*i+1,num);
    if(tmp!=-1)
        return tmp;
    else
        return find(2*i,num);
}

void insert(int i,int x,int y,long long num)
{
    push_down(i);
    int l=a[i].l,r=a[i].r;
    if(l==x&&r==y)
    {
        a[i].x=num;
        a[i].y=num;
        a[i].sum=(r-l+1)*num;
        a[i].lazy=num;
        return;
    }
    int mid=(l+r)/2;
    if(y<=mid)
        insert(2*i,x,y,num);
    else if(x>=mid+1)
        insert(2*i+1,x,y,num);
    else
    {
        insert(2*i,x,mid,num);
        insert(2*i+1,mid+1,y,num);
    }
    push_up(i);
}

void update(int x,int y,int num)
{
    if(x>y)
        return;
    int tmp=find(1,num);
    tmp=min(tmp,y);
    if(tmp>=x)
        insert(1,x,tmp,num);
}

int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        int tmp;
        scanf("%d",&tmp);
        for(int j=1;j*j<=tmp;j++)
        {
            if(tmp%j==0)
            {
                v[j].push_back(i);
                if(j*j!=tmp)
                    v[tmp/j].push_back(i);
            }
        }
    }
    for(int i=1;i<=200000;i++)
        sort(v[i].begin(),v[i].end());

    /*
    for(int i=1;i<=16;i++)
    {
        for(int j=0;j<v[i].size();j++)
            cout<<v[i][j]<<" ";
        cout<<endl;
    }
    */

    init(1,1,n);
    for(int i=200000;i>=1;i--)
    {
        h[i]=(long long)n*(n+1)-a[1].sum;
        int siz=v[i].size();
        if(siz<=1)
            continue;
        else if(siz==2)
        {
            int op=v[i][0],ed=v[i][1];
            update(1,op-1,op);
            update(op+1,ed-1,ed);
            update(ed+1,n,n+1);
        }
        else
        {
            update(1,v[i][0],v[i][siz-2]);
            update(v[i][0]+1,v[i][1],v[i][siz-1]);
            update(v[i][1]+1,n,n+1);
        }
    }

    h[0]=3;
    long long ans=0;
    for(int i=1;i<=200000;i++)
        ans+=(h[i]-h[i-1])*i;
    printf("%I64d\n",ans);

    return 0;
}


#include <algorithm>
#include <cstdio>
#include <cstring>
#include <string>
#include <queue>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
const int int_inf = 0x3f3f3f3f;
const double double_inf = 1e10 * 1e10;
typedef unsigned long long ul;
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define mp make_pair
#define st first
#define nd second
#define pii pair<int, int>
#define pb push_back
#define type(x) __typeof(x.begin())
#define foreach(i, j) for(type(j)i = j.begin(); i != j.end(); i++)
#define FOR(i, s, t) for(int i = s; i <= t; i++)
#define ROF(i, t, s) for(int i = t; i >= s; i--)
int debug = 0;

//-------------------------------------------------------------------------
const int maxn = 2e5 + 10;
int a[maxn], n;
ll sum;
ll ans[maxn];
set<pair<pii, int> > S;
vector<int> H[maxn], v[maxn];
set<pair<pii, int> > :: iterator it, it2;
//-------------------------------------------------------------------------

void divide(int x){
    it = S.lower_bound(mp(mp(x + 1, 0), -1));
    if(it == S.begin()) return;
    --it;
    pair<pii, int> t = *it;
    if(t.st.nd < x) return;
    S.erase(it);
    S.insert(mp(mp(t.st.st, x), t.nd));
    if(t.st.nd >= x + 1) S.insert(mp(mp(x + 1, t.st.nd), t.nd));
}

void remove(int x){
    divide(x - 1);
    while(S.rbegin()->st.st >= x){
        pair<pii, int> t = *S.rbegin();
        sum -= (ll)t.nd * (t.st.nd - t.st.st + 1);
        S.erase(t);
    }
}

void maximize(int l, int r, int maxi){
    it = S.lower_bound(mp(mp(l, 0), 0));
    pair<pii, int> t;
    t.st.st = l, t.nd = maxi;
    while(it != S.end()){
        if(it->nd >= maxi) break;
        if(it->st.st > r) break;
        t.st.nd = it->st.nd;
        sum -= (ll)it->nd * (it->st.nd - it->st.st + 1);
        it2 = it; it2++; S.erase(it); it = it2;
    }
    if(t.st.st <= t.st.nd){
        sum += (ll)t.nd * (t.st.nd - t.st.st + 1);
        S.insert(t);
    }
}

int main(){
    if(debug) freopen("in.txt", "r", stdin);
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
    while(~scanf("%d", &n)){
        sum = 0;
        S.clear();
        FOR(i, 0, maxn - 1) v[i].clear(), H[i].clear();
        FOR(i, 1, n){
            scanf("%d", &a[i]);
            sum += i;
            H[a[i]].pb(i);
            S.insert(mp(mp(i, i), i));
        }
        FOR(i, 1, maxn - 1){
            for(int j = i; j < maxn; j += i)
                foreach(it, H[j]) v[i].pb(*it);
        }
        ans[maxn - 1] = (ll)n * (n + 1) >> 1;
        ROF(i, maxn - 2, 1){
            int l = v[i].size() - 1;
            if(l <= 0) { ans[i] = ans[i + 1]; continue; }
            sort(v[i].begin(), v[i].end());
            remove(v[i][1] + 1);
            divide(v[i][0]);
            maximize(v[i][0] + 1, n, v[i][l]);
            maximize(1, v[i][0], v[i][l - 1]);
          //  divide(v[i][0]);
           // maximize(v[i][0] + 1, v[i][l]);
            ans[i] = (ll)S.rbegin()->st.nd * (n + 1) - sum;
        }
        ll tot = 0;
        ans[0] = 0;
        FOR(i, 1, maxn - 2) tot += (ll)i * (ans[i + 1] - ans[i]);
        printf("%lld\n", tot);
    }

    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
    return 0;
}


/*
    assume that a[x] and a[y]'s gcd is largest
    if the interval [i,j] deleted not included subscript x or y, then f(i,j) still equal to gcd(a[x], a[y])
    therefore we enumerate the maximum of gcd(from max(a[1..n]) down to 1)
    for each gcdi we enumerate there may exist some element in array a[] which can be divided by gcdi
    we record their subscript then sort these subscripts
    assume there are k elements we record (k >= 2)
    it's clear that only three situations should be thought about
    1. we reserve the first and second sorted elements we record
       that is we can remove any interval[i, j] in interval[a[second]+1, n], and f(i, j) still equals to gcdi
    2. we reserve last two sorted elements we record
       that is we can remove any interval[i, j] in interval[1, a[k-1]-1], and f(i, j) still equals to gcdi
    3. we reserve the first and last sorted elements we record
       that is we can remove any interval[i, j] in interval[a[first]+1, a[last]-1], and f(i,j) still equals to gcdi
    then we donate board[i] as we can remove any interval[i, j] in interval[i, board[i]] it's clear that board[i] should be maximum
    if board[i] equals to n+1 we say all of intervals started with subscript i can be removes and then we will not care it any more
    we set cnt[1] donating the sum of remaining intervals should be removed and the initial of cnt[1] = n*(n+1)/2 and tot_cnt = n*(n+1)
    if there are another x intervals be removed, then we add x to cnt[1] (cnt[1] = cnt[1'] + x)
    the sum of remaining intervals should be removed equals tot_cnt - cnt[1] (cnt_inv[gcdi-1] = tot_cnt - cnt[1])
    and x equals to cnt_inv[gcdi] - cnt_inv[gcdi-1] (cnt_inv[gcdi] - cnt_inv[gcdi-1] = tot_cnt - cnt[1'] - (tot_cnt - (cnt[1'] + x)) = -cnt[1'] + cnt[1'] + x = x)
    and the contribution of gcdi to answer equals to (cnt_inv[gcdi] - cnt_inv[gcdi-1]) * gcdi
*/
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <ctime>
#include <conio.h>
#include <iomanip>

using namespace std;
typedef long long LL;

const int MAXN = 200000 + 5;

int n;
int a[MAXN];
int exist[MAXN];
int _max;
int lazy[4*MAXN];
int board[4*MAXN];
long long cnt[4*MAXN];
long long tot_inv, cnt_inv[MAXN];

void pushup(int index) {
    board[index] = min(board[index*2], board[index*2+1]);
    cnt[index] = cnt[index*2] + cnt[index*2+1];
}

void pushdown(int index) {
    if (lazy[index] == 1) {
        long long s  = (cnt[index]/board[index]) / 2 + (cnt[index]/board[index]) % 2;
        cnt[index*2] = s * board[index];
        cnt[index*2+1] = cnt[index] - s * board[index];
        board[index*2] = board[index*2+1] = board[index];
        lazy[index*2] = lazy[index*2+1] = 1;
        lazy[index] = 0;
    }
}

void build(int index, int l, int r) {
    if (l == r) {
        board[index] = l;
        cnt[index] = l;
        return;
    }

    int mid = (l+r) / 2;
    build(index*2, l, mid);
    build(index*2+1, mid+1, r);
    pushup(index);
}

void update(int index, int l, int r, int left, int right, int BOARD) {
    if (left <= l && right >= r) {
        if (BOARD > board[index]) {
            board[index] = BOARD;
            cnt[index] = LL(r-l+1) * BOARD;
            lazy[index] = 1;
        }
        return;
    }
    pushdown(index);
    int mid = (l+r) / 2;
    if (left <= mid)
        update(index*2, l, mid, left, right, BOARD);
    if (mid+1 <= right)
        update(index*2+1, mid+1, r, left, right, BOARD);
    pushup(index);
}

int find(int index, int l, int r, int BOARD) {
    if (l == r)
        return l;

    int mid = (l+r) / 2;
    pushdown(index);
    if (board[index*2+1] < BOARD)
        return find(index*2+1, mid+1, r, BOARD);
    else
        return find(index*2, l, mid, BOARD);
}

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
    }

    memset(exist, 0, sizeof(exist));
    for (int i = 1; i <= n; i++) {
        exist[a[i]] = i;
        _max = max(_max, a[i]);
    }

    build(1, 1, n);
    tot_inv = LL(n) * (n+1);
    cnt_inv[_max+1] = tot_inv - cnt[1]; cnt_inv[0] = 3;
    for (int i = _max; i >= 1; i--) {
        vector<int> v;

        v.clear();
        for (int j = i; j <= _max; j += i) {
            if (exist[j] > 0)
                v.push_back(exist[j]);
        }

        cnt_inv[i] = tot_inv - cnt[1];
        int k = v.size();
        if (k < 2)
            continue;

        sort(v.begin(), v.end());
        if (v[1]+1 <= n) {
            update(1, 1, n, v[1]+1, n, n+1);
        }
        if (board[1] < v[k-1]) {
            int pos = find(1, 1, n, v[k-1]);
            pos = min(pos, v[k-1]-1);
            update(1, 1, n, v[0]+1, pos, v[k-1]);
        }
        if (board[1] < v[k-2]) {
            int pos = find(1, 1, n, v[k-2]);
            pos = min(pos, v[k-2]-1);
            update(1, 1, n, 1, pos, v[k-2]);
        }
    }

    long long ans = 0;
    for (int i = _max; i >= 1; i--)
        ans += LL(cnt_inv[i]-cnt_inv[i-1]) * i;

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


/*
CFR-350 2E
set/线段树+思维 好题
https://www.cnblogs.com/Blue233333/p/8075440.html
https://blog.csdn.net/u010734277/article/details/51538249 (官方题解译文)
http://codeforces.com/blog/entry/44821 (官方题解)
*/
//线段树
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5+5;
ll H[N];
int a[N];
ll c[N<<2];//sum
ll s[N<<2];//min
ll lz[N<<2];//lazy
vector<int> v[N];//ve[i]:i的倍数的下标
int u,yl,yr;
void build(int o, int l, int r){
    if (l==r){
        lz[o]=l;
        c[o]=l;
        s[o]=l;
        return;
    }
    int mid=(l+r)>>1;
    build(o<<1,l,mid);
    build(o<<1|1,mid+1,r);
    lz[o]=-1;
    c[o]=c[o<<1]+c[o<<1|1];
    s[o]=min(s[o<<1],s[o<<1|1]);
}
void pushdown(int o, int l, int r){
    if (l==r) return;
    if (lz[o]==-1) return;
    lz[o<<1]=lz[o]; lz[o<<1|1]=lz[o];
    s[o<<1]=lz[o]; s[o<<1|1]=lz[o];
    int mid=(l+r)>>1;
    c[o<<1]=lz[o]*(mid-l+1);
    c[o<<1|1]=lz[o]*(r-mid);
    lz[o]=-1;
}
void upd(int o, int l, int r){
    if (yl<=l&&yr>=r){
        c[o]=1LL*u*(r-l+1);
        s[o]=u;
        lz[o]=u;
        return;
    }
    pushdown(o,l,r);
    int mid=(l+r)>>1;
    if (yl<=mid) upd(o<<1,l,mid);
    if (yr>mid) upd(o<<1|1,mid+1,r);
    c[o]=c[o<<1]+c[o<<1|1];
    s[o]=min(s[o<<1],s[o<<1|1]);
    if (lz[o<<1]==lz[o<<1|1]&&lz[o<<1]>=0) lz[o]=lz[o<<1];
}
int query(int o, int l, int r){//返回小于k的最右侧的nexti的下标i
    if (l==r&&c[o]<u) return l;
    if (l==r&&c[o]>=u) return 0;
    if (lz[o]!=-1&&lz[o]<u) return r;
    if (lz[o]!=-1&&lz[o]>=u) return 0;
    int mid=(l+r)>>1;
    if (s[o<<1|1]<u) return query(o<<1|1,mid+1,r);
    else return query(o<<1,l,mid);
}
int main(){
    int n; scanf("%d",&n);
    int mx=-1;
    memset(a,0,sizeof(a));
    for (int i=1; i<=n; i++){
        int tmp; scanf("%d",&tmp);
        a[tmp]=i;//保证所有元素都不同
        mx=max(mx,tmp);
    }
    for (int i=1; i<=mx; i++){
        for (int j=1; j*i<=mx; j++){
            if (a[j*i]) v[i].push_back(a[j*i]);
        }
    }
    for (int i=0; i<=mx; i++) sort(v[i].begin(),v[i].end());
    ll sum=1LL*n*(n+1);
    build(1,1,n);
    for (int i=mx; i>=0; i--){
        H[i]=sum-c[1];
        int k=v[i].size();
        if (k<2) continue;
        u=n+1;
        yl=v[i][1]+1; yr=n;
        if (yl<=yr) upd(1,1,n);//成段更新

        u=v[i][k-1];
        int pos=query(1,1,n);//Returns rightmost index i where nexti is less than some k
        pos=min(pos,v[i][1]);
        if (pos>v[i][0]&&pos<=v[i][1]){
            yl=v[i][0]+1,yr=pos;
            upd(1,1,n);
        }

        u=v[i][k-2];
        pos=query(1,1,n);
        pos=min(pos,v[i][0]);
        if (pos>=1&&pos<=v[i][0]){
            yl=1,yr=pos;
            upd(1,1,n);
        }
    }
    ll ans=0;
    for (int i=1; i<=mx; i++) ans+=1LL*i*(H[i]-H[i-1]);
    cout<<ans<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define reset(a, x) memset(a, x, sizeof(a))

const int MAX = (int)2E5 + 10;

int n;
int l1[MAX], l2[MAX], r1[MAX], r2[MAX];
long long h[MAX];

struct node{
    long long s;
    int l, mn, mx;
};

node smt[4*MAX];

void combine(int id, int c1, int c2){
    smt[id].s = smt[c1].s + smt[c2].s;
    smt[id].mn = min(smt[c1].mn, smt[c2].mn);
    smt[id].mx = max(smt[c1].mx, smt[c2].mx);
}

void update(int id, int l, int r, int x, int y, int v){
    if(y < l || x > r || smt[id].mn >= v) return;
    if(x <= l && r <= y && smt[id].mx <= v){
        smt[id].mn = smt[id].mx = smt[id].l = v;
        smt[id].s = (long long)(r - l + 1)*v;
        return;
    }
    int c1 = id*2 + 1; int c2 = id*2 + 2; int mid = (l + r)/2;
    if(smt[id].l != -1){
        smt[c1].mn = smt[c1].mx = smt[c1].l = smt[c2].mn = smt[c2].mx = smt[c2].l = smt[id].l;
        smt[c1].s = (long long)(mid - l + 1)*smt[id].l;
        smt[c2].s = (long long)(r - (mid + 1) + 1)*smt[id].l;
        smt[id].l = -1;
    }
    update(c1, l, mid, x, y, v);
    update(c2, mid + 1, r, x, y, v);
    combine(id, c1, c2);
}

void update(int x, int y, int v){
    update(0, 0, n - 1, x, y, v);
}

void build(int id, int l, int r){
    smt[id].l = -1;
    if(l == r){
        smt[id].mn = smt[id].mx = smt[id].s = l;
    }else{
        int c1 = id*2 + 1; int c2 = id*2 + 2;

        build(c1, l, (l + r)/2);
        build(c2, (l + r)/2 + 1, r);

        combine(id, c1, c2);
    }
}

int main(){
//    freopen("e.in", "r", stdin);
//    freopen("e.out", "w", stdout);
    reset(l1, 255); reset(l2, 255); reset(r1, 255); reset(r2, 255);
    scanf("%d", &n);
    for(int i = 0; i < n; i++){
        int a;
        scanf("%d", &a);
        for(int j = 1; j <= (int)sqrt(a); j++)
        if(a%j == 0){
            if(l1[j] == -1) l1[j] = i;
            else if(l2[j] == -1) l2[j] = i;
            r2[j] = r1[j]; r1[j] = i;

            if(a/j != j){
                if(l1[a/j] == -1) l1[a/j] = i;
                else if(l2[a/j] == -1) l2[a/j] = i;
                r2[a/j] = r1[a/j]; r1[a/j] = i;
            }
        }
    }

    build(0, 0, n - 1);
    for(int i = 2E5 + 1; i >= 1; i--){
        if(l1[i] != -1 && l2[i] != -1){
            update(l2[i] + 1, n - 1, n);
            update(l1[i] + 1, l2[i], r1[i]);
            update(0, l1[i], r2[i]);
        }
        h[i - 1] = (long long)n*n - smt[0].s;
    }
//    cout << smt[0].s << endl;

    long long res = 0;
    for(int i = 1; i < 2E5 + 1; i++) res += (h[i] - h[i - 1])*i;

//    for(int i = 0; i < 10; i++) cout << h[i] << endl;

    printf("%I64d", res);
}


/*
 * Problem: cf 672 E
 * User: Yuuki_Asuna
 * Data: 2016/5/24
 */

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <cstring>

using namespace std;

#define N 200008
#define M 200005

int n;
int a[N],l1[N],r1[N],l2[N],r2[N];
long long h[N];

struct Tree
{
	int maxn[4*N],minn[4*N],flag[4*N];
	long long sum[4*N];

	inline void mark(int p,int l,int r,int x)
	{
		maxn[p] = minn[p] = x;
		sum[p] = (long long)x*(r-l+1);
		flag[p] = x;
	}

	inline void push_down(int p,int l,int r)
	{
		if (flag[p])
		{
			if (l == r)	return;
			int mid = (l+r) >> 1;
			mark(p*2,l,mid,flag[p]);
			mark(p*2+1,mid+1,r,flag[p]);
			flag[p] = 0;
		}
	}

	void insert(int p,int l,int r,int ll,int rr,int x)
	{
		if (minn[p] >= x)	return;
		if(ll <= l && rr >= r && x >= maxn[p])
		{
			mark(p,l,r,x);
			return;
		}
		if (l == r)	return;
		push_down(p,l,r);
		int mid = (l+r) >> 1;
		if (ll <= mid)	insert(p*2,l,mid,ll,rr,x);
		if (rr > mid)	insert(p*2+1,mid+1,r,ll,rr,x);
		maxn[p] = max(maxn[p*2],maxn[p*2+1]);
		minn[p] = min(minn[p*2],minn[p*2+1]);
		sum[p] = sum[p*2] + sum[p*2+1];
	}

}T;

void init()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
		scanf("%d", &a[i]);
}

inline void add(int j,int i)
{
	if (!l1[j])	l1[j] = i;
	else if (!l2[j]) l2[j] = i;
	r1[j] = r2[j];
	r2[j] = i;
}

void prepare()
{
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= (int)sqrt((double)a[i]); j++)
		{
			if (a[i] % j != 0)	continue;
			add(j,i);
			if (a[i] / j == j)	continue;
			add(a[i]/j,i);
		}
	}
}

void work()
{
	prepare();
	long long ans = 0;
	for (int i = 1; i <= n; i++)
		T.insert(1,1,n,i,i,i);
	h[M] = (long long)n*(n+1)/2;
	for (int i = M-1; i >= 0; i--)
	{
		h[i] = h[i+1];
		if (l1[i] == r2[i])	continue;
		T.insert(1,1,n,1,l1[i],r1[i]);
		T.insert(1,1,n,l1[i]+1,l2[i],r2[i]);
		if (l2[i]+1 <= n)
			T.insert(1,1,n,l2[i]+1,n,n+1);
		h[i] = (long long)n*(n+1)-T.sum[1];
	}
	for (int i = 1; i < M; i++)
		ans += ((long long)h[i] - h[i-1]) * (i-1);
	printf("%I64d\n", ans);
}

int main()
{
	init();
	work();
	return 0;
}


#pragma comment(linker, "/STACK:102400000,102400000")
#pragma GCC optimize("O3")
#pragma GCC diagnostic error "-std=c++11"
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;
#define inf          0x3f3f3f3f
#define go(a,b,c)    for(int a=b;a<=c;++a)
#define gov(a,b)     for(int a=0;a<b.size();++a)
#define rgo(a,b,c)   for(int a=b;a>=c;--a)
#define sf(a)        scanf("%d",&a)
#define sff(a,b)     scanf("%d%d",&a,&b)
#define sfff(a,b,c)  scanf("%d%d%d",&a,&b,&c)
#define eps          1e-9
#define ft           first
#define sd           second
#define prt(a)       printf("%d\n",a)
#define prn(i,n,a)   printf("%d%c",a,i==n?'\n':' ')
#define pb           push_back
#define D(v)         cerr<<#v<<"   "<<v<<endl;
#define lowbit(x)    ((x)&(-x))
#define all(a)       a.begin(),a.end()
typedef long long LL;
typedef pair<int,int> pii;
typedef set<int> si;
typedef vector<int> vi;
typedef map<int,int> mii;
typedef double db;
const int maxn=2e5+10;
const LL mod=1e9+7;
inline int inverse(int a){return a <= 1 ? 1 : (LL)(mod - mod / a) * inverse(mod % a) % mod;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
LL fsp(LL a,LL b){LL ans=1;for(;b;a=a*a%mod,b>>=1)if(b&1)ans=ans*a%mod;return ans%mod;}
inline void read(int &x)
{
	x=0;
	int f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch<='9'&&ch>='0'){x=x*10+ch-'0';ch=getchar();}
}
//=======================================================
struct segtree
{
	LL f[maxn*4],mn[maxn*4];
	void push_up(int rt)
	{
		int ls=rt<<1,rs=rt<<1|1;
		mn[rt]=min(mn[ls],mn[rs]);
		f[rt]=f[ls]+f[rs];
	}
	void build(int rt,int l,int r)
	{
		if(l==r){f[rt]=mn[rt]=l;return;}
		int m=(l+r)/2,ls=rt<<1,rs=rt<<1|1;
		build(ls,l,m);
		build(rs,m+1,r);
		push_up(rt);
	}
	void push_down(int rt,int l,int r,int val)
	{
		if(mn[rt]>=val)return;
		if(l==r){mn[rt]=f[rt]=val;return;}
		int m=(l+r)/2,ls=rt<<1,rs=rt<<1|1;
		if(mn[ls]<val)push_down(ls,l,m,val);
		if(mn[rs]<val)push_down(rs,m+1,r,val);
		push_up(rt);
	}
	void change(int rt,int l,int r,int L,int R,int val)
	{
		if(l>=L&&r<=R){push_down(rt,l,r,val);return;}
		int m=(l+r)/2,ls=rt<<1,rs=rt<<1|1;
		if(m>=L)change(ls,l,m,L,R,val);
		if(m<R)change(rs,m+1,r,L,R,val);
		push_up(rt);
	}
}st;
LL h[maxn];
int n,a[maxn];
vi v[maxn],k[maxn];
void work()
{
	st.build(1,1,n);
	memset(h,0,sizeof(h));
	D(st.f[1]);
	int mx=0;
	go(i,1,n)
	{
		int x;sf(x);mx=max(mx,x);a[i]=x;
		for(auto it : v[x])
			k[it].pb(i);
	}
	h[mx+1]=1LL*(n+1)*n-st.f[1];
	for(int i=mx;i>=1;i--)
	{
		if(k[i].size()>=2)
		{
			int sz=(int)k[i].size();
			st.change(1,1,n,1,k[i][0],k[i][sz-2]);
			st.change(1,1,n,k[i][0]+1,k[i][1],k[i][sz-1]);
			if(k[i][1]+1<=n)st.change(1,1,n,k[i][1]+1,n,n+1);
		//	if(k[i][sz-1]==n&&k[i][sz-2]==n-1)st.change(1,1,n,1,1,n+1);
		//	if(k[i][0]==1&&k[i][sz-1]==n)st.change(1,1,n,2,2,n+1);
		}
		h[i]=1LL*(n+1)*n-st.f[1];
	}
	LL ans=0;
	go(i,1,mx)
	{
	//	D(h[i]);
		ans+=1LL*(h[i+1]-h[i])*i;
	}
	cout<<ans<<endl;
}
int main()
{
	go(i,1,200000)
		for(int j=i;j<=200000;j+=i)
			v[j].pb(i);
	while(~sf(n))work();
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
typedef long long ll;
ll H[200005];
int a[200005];
ll c[200005 << 2];
ll s[200005 << 2];
ll lz[200005 << 2];
vector<int> v[200005];

int u;
int yl,yr;
void build(int o,int l,int r)
{
    if(l == r){
        lz[o] = l;
        c[o] = l;s[o] = l;return;
    }
    int mid = (l+r) >> 1;
    build(o*2,l,mid);
    build(o*2+1,mid+1,r);
    lz[o] = -1;
    c[o] = c[o*2] + c[o*2+1];
    s[o] = min(s[o*2],s[o*2+1]);
}

void pushdown(int o,int l,int r)
{
    if(l == r)return;
    if(lz[o] == -1)return;
    lz[o * 2] = lz[o];lz[o*2+1] = lz[o];
    s[o*2] = lz[o];s[o*2+1]=lz[o];
    int mid = (l+r) >> 1;
    c[o*2] = lz[o] * (mid - l + 1);
    c[o*2+1] = lz[o] * (r - mid);
    lz[o] = -1;
}

void update(int o,int l,int r)
{
    if(yl <= l && yr >= r){
        c[o] = 1LL * u *(r - l + 1);
        s[o] = u;
        lz[o] = u;return;
    }
    pushdown(o,l,r);
    int mid = (l + r) >> 1;
    if(yl <= mid)update(o*2,l,mid);
    if(yr > mid) update(o*2+1 , mid+1,r);
    c[o] = c[o*2] + c[o*2+1];
    s[o] = min(s[o*2],s[o*2+1]);
    if(lz[o*2] == lz[o*2+1] && lz[o*2] >= 0)lz[o] = lz[o*2];
}

int query(int o,int l,int r)
{
    if(l == r && c[o] < u )return l;
    if(l == r && c[o] >=u )return 0;
    if(lz[o]!=-1 && lz[o] < u)return r;
    if(lz[o] != -1 && lz[o] >= u)return 0;
    int mid = (l+r)>>1;
    if(s[o*2+1] < u)return query(o*2+1,mid+1,r);
    else return query(o*2,l,mid);
}

int main()
{
//    freopen("data.txt","r",stdin);
    int n;
    scanf("%d",&n);
    int mx = -1;
    memset(a,0,sizeof(a));
    for(int i = 1; i < n+1 ; ++i){
        int tmp;
        scanf("%d",&tmp);
        a[tmp] = i;
        mx = max(mx,tmp);
    }
    for(int i = 1; i <=mx; ++i){
        for(int j = 1;j*i<=mx;++j){
            if(a[j*i])
                v[i].push_back(a[j*i]);
        }
    }
    for(int i = 0; i <= mx;++i)sort(v[i].begin(),v[i].end());
    ll sum =1LL * n * (n+1);
    build(1,1,n);
    for(int i = mx; i >= 0; --i){
        H[i] = sum - c[1];
        int k = v[i].size();
        if(k < 2){continue;}
        u = n + 1;
        yl = v[i][1]+1;yr = n;
        if(yl <= yr)
            update(1,1,n);

        u = v[i][k-1];
        int pos = query(1,1,n);
        pos = min(pos , v[i][1]);
        if(pos > v[i][0] && pos <= v[i][1]){
            yl = v[i][0] + 1;yr = pos;
            update(1,1,n);
        }

        u = v[i][k-2];
        pos = query(1,1,n);
        pos = min(pos , v[i][0]);
        if(pos >= 1 && pos <= v[i][0]){
            yl = 1;yr = pos;
            update(1,1,n);
        }

    }
    ll ans = 0;
    for(int i = 1 ;i <= mx; ++i){
        ans += 1LL * i * (H[i] - H[i-1]);
    }
    printf("%I64d\n",ans);
}


// God & me
// The life is over ; (
#include <bits/stdc++.h>
#define pb push_back
#define X first
#define Y second
#define int long long
using namespace std;
template <class T, class L> bool smax(T &x,L y){  return x < y ? (x = y, 1) : 0;  }
template <class T, class L> bool smin(T &x,L y){  return y < x ? (x = y, 1) : 0;  }
typedef pair<int, int> pii;

const int maxn = 2e5 + 17;
int iman[maxn << 2], sina[maxn << 2], n, a[maxn], dj[maxn << 2];
void majid(int l = 0, int r = n, int id = 1){
    dj[id] = l;
    if(l + 1 == r){
	iman[id] = l;
	return ;
    }
    int mid = l + r >> 1;
    majid(l, mid, id << 1), majid(mid, r, id << 1 | 1);
    iman[id] = iman[id << 1] + iman[id << 1 | 1];
}
void upd(int l, int r, int id, int x){
    iman[id] = x * (r - l);
    dj[id] = sina[id] = x;
}
void sadra(int l, int r, int id){
    if(sina[id] == -1)  return;
    int mid = l + r >> 1;
    upd(l, mid, id << 1, sina[id]);
    upd(mid, r, id << 1 | 1, sina[id]);
    sina[id] = -1;
}
void arpa(int s, int e, int x, int l = 0, int r = n, int id = 1){
    if(s <= l && r <= e){
	upd(l, r, id, x);
	return;
    }
    if(e <= l || r <= s)  return;
    sadra(l, r, id);
    int mid = l + r >> 1;
    arpa(s, e, x, l, mid, id << 1), arpa(s, e, x, mid, r, id << 1 | 1);
    iman[id] = iman[id << 1] + iman[id << 1 | 1];
    dj[id] = dj[id << 1];
}
int doktor(int s, int e, int x, int l = 0, int r = n, int id = 1){
    if(e <= l || r <= s || dj[id] > x)  return -1;
    if(l + 1 == r)  return l;
    int mid = l + r >> 1, ans = doktor(s, e, x, mid, r, id << 1 | 1);
    return ~ans ? ans : doktor(s, e, x, l, mid, id << 1);
}
void amir(int s, int e, int x){  arpa(s, doktor(s, e, x) + 1, x);  }
vector<int>mp[maxn], ass[maxn];
int ps[maxn];
main(){
    ios::sync_with_stdio(0), cin.tie(0);
    cin >> n;
    for(int i = 0; i < n; i++)
	cin >> a[i], mp[ a[i] ].pb(i);
    majid();
    for(int i = 1; i < maxn; i++){
	for(int j = i; j < maxn; j += i)
	    ass[i].insert(ass[i].end(), mp[j].begin(), mp[j].end());
	sort(ass[i].begin(), ass[i].end());
	ass[i].resize( unique(ass[i].begin(), ass[i].end()) - ass[i].begin() );
    }
    for(int i = maxn - 1; ~i; i--){
	ps[i] = n * n - iman[1];
	if(ass[i].size() <= 1)  continue;
	amir(0, ass[i][0] + 1, ass[i][ ass[i].size() - 2]);
	amir(ass[i][0] + 1, ass[i][1] + 1, ass[i].back());
	amir(ass[i][1] + 1, n, n);
    }
    int ans = 0;
    for(int i = 1; i < maxn - 1; i++)
	ans += (ps[i] - ps[i - 1]) * i;
    cout << ans << '\n';
    return 0;
}


#include <iostream>
#include <vector>
#include <map>
#define F first
#define S second
using namespace std;
int n;

vector<int> fc[202020];
vector<int> tkj[202020];

map<long long, long long> vl;
map<long long, long long>::iterator it, it2;

long long gv(long long a, long long b){
  if (a>b) return 0;
  long long m=0;
  it=vl.upper_bound(a); --it;
  long long la=(*it).F;
  long long lb=(*it).S;
  if (lb>=b) return 0;
  while (1){
    long long ia=(*it).F;
    long long ib=(*it).S;
    m+=(b-lb)*(ia-la);
    la=max(a, ia); lb=ib;
    if (ib>b || ia>b) break;
    it2=it; ++it2;
    if (ia>=a) vl.erase(it);
    it=it2;
  }
  vl[a]=b;
  return m;
}

int main(){
  ios_base::sync_with_stdio(0); cin.tie(0);
  for (int i=1; i<202020; ++i) for (int j=i; j<202020; j+=i) fc[j].push_back(i);
  cin >> n;
  vl[n]=n;
  for (int i=0; i<n; ++i){
    int ai;
    cin >> ai;
    for (int j=0; j<fc[ai].size(); ++j) tkj[fc[ai][j]].push_back(i);
  }
  for (int i=-1; i<n+1; ++i) vl[i]=i-1;
  long long sm=0;
  for (int tk=202020; tk; --tk){
    if (tkj[tk].size()<2) continue;
    int a=tkj[tk][0];
    int b=tkj[tk][1];
    int c=tkj[tk][tkj[tk].size()-2];
    int d=tkj[tk][tkj[tk].size()-1];
    sm+=tk*gv(0, c-1);
    sm+=tk*gv(b+1, n-1);
    sm+=tk*gv(a+1, d-1);
  }
  cout << sm << "\n";
}


#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <ctime>
#include <conio.h>
#include <iomanip>

using namespace std;
typedef long long LL;

const int MAXN = 200000 + 5;

int n;
int a[MAXN];
int exist[MAXN];
int _max;
int lazy[4*MAXN];
int board[4*MAXN];
long long cnt[4*MAXN];
long long tot_inv, cnt_inv[MAXN];

void pushup(int index) {
    board[index] = min(board[index*2], board[index*2+1]);
    cnt[index] = cnt[index*2] + cnt[index*2+1];
}

void pushdown(int index) {
    if (lazy[index] == 1) {
        long long s  = (cnt[index]/board[index]) / 2 + (cnt[index]/board[index]) % 2;
        cnt[index*2] = s * board[index];
        cnt[index*2+1] = cnt[index] - s * board[index];
        board[index*2] = board[index*2+1] = board[index];
        lazy[index*2] = lazy[index*2+1] = 1;
        lazy[index] = 0;
    }
}

void build(int index, int l, int r) {
    if (l == r) {
        board[index] = l;
        cnt[index] = l;
        return;
    }

    int mid = (l+r) / 2;
    build(index*2, l, mid);
    build(index*2+1, mid+1, r);
    pushup(index);
}

void update(int index, int l, int r, int left, int right, int BOARD) {
    if (left <= l && right >= r) {
        if (BOARD > board[index]) {
            board[index] = BOARD;
            cnt[index] = LL(r-l+1) * BOARD;
            lazy[index] = 1;
        }
        return;
    }
    pushdown(index);
    int mid = (l+r) / 2;
    if (left <= mid)
        update(index*2, l, mid, left, right, BOARD);
    if (mid+1 <= right)
        update(index*2+1, mid+1, r, left, right, BOARD);
    pushup(index);
}

int find(int index, int l, int r, int BOARD) {
    if (l == r)
        return l;

    int mid = (l+r) / 2;
    pushdown(index);
    if (board[index*2+1] < BOARD)
        return find(index*2+1, mid+1, r, BOARD);
    else
        return find(index*2, l, mid, BOARD);
}

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
    }

    memset(exist, 0, sizeof(exist));
    for (int i = 1; i <= n; i++) {
        exist[a[i]] = i;
        _max = max(_max, a[i]);
    }

    build(1, 1, n);
    tot_inv = LL(n) * (n+1);
    cnt_inv[_max+1] = tot_inv - cnt[1]; cnt_inv[0] = 3;
    for (int i = _max; i >= 1; i--) {
        vector<int> v;

        v.clear();
        for (int j = i; j <= _max; j += i) {
            if (exist[j] > 0)
                v.push_back(exist[j]);
        }

        cnt_inv[i] = tot_inv - cnt[1];
        int k = v.size();
        if (k < 2)
            continue;

        sort(v.begin(), v.end());
        if (v[1]+1 <= n) {
            update(1, 1, n, v[1]+1, n, n+1);
        }
        if (board[1] < v[k-1]) {
            int pos = find(1, 1, n, v[k-1]);
            pos = min(pos, v[k-1]-1);
            update(1, 1, n, v[0]+1, pos, v[k-1]);
        }
        if (board[1] < v[k-2]) {
            int pos = find(1, 1, n, v[k-2]);
            pos = min(pos, v[k-2]-1);
            update(1, 1, n, 1, pos, v[k-2]);
        }
    }

    long long ans = 0;
    for (int i = _max; i >= 1; i--)
        ans += LL(cnt_inv[i]-cnt_inv[i-1]) * i;

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


#include<bits/stdc++.h>
using namespace std;
const int N = 2e5+7;
#define div Div
vector<int> div[N];
int L[N], a[N], ps[N], toset[4*N], n;
typedef long long ll;
ll seg[4*N], mx[4*N];
inline void makeL()
{
	for (int i = 0; i < N; i++) L[i] = n;
	for (int i = 0; i < n; i++)
		L[a[i]] = min(L[a[i]], i);
	L[1] = 0;
	for (int i = 2; i < N; i++)
		for (int j = i; j < N; j += i)
			L[i] = min(L[i], L[j]);
}
inline void divisor()
{
	for (int i = 1; i < N; i++)
	{
		for (int j = i; j < N; j += i)
			div[j].push_back(i);
		div[i].shrink_to_fit();
	}
}
inline void fix (int xl, int xr, int k, int val)
{
	toset[k] = mx[k] = val;
	seg[k] = 1ll * (xr - xl) * val;
}
inline void shift(int xl, int xr, int k)
{
	if (toset[k] == -1) return;
	int val = toset[k];
	toset[k] = -1;
	int xm = (xl+xr) / 2;
	fix(xl, xm, 2*k+1, val);
	fix(xm, xr, 2*k+2, val);
}
void Set(int ql, int qr, int val, int xl = 0, int xr = N, int k = 0)
{
	if (ql >= xr || qr <= xl) return;
	if (ql <= xl && qr >= xr)
	{
		fix(xl, xr, k, val);
		return;
	}
	shift(xl, xr, k);
	int xm = (xl+xr) / 2;
	Set(ql, qr, val, xl, xm, 2*k+1);
	Set(ql, qr, val, xm, xr, 2*k+2);
	seg[k] = seg[2*k+1] + seg[2*k+2];
	mx[k] = max(mx[2*k+1], mx[2*k+2]);
}
ll get (int ql, int qr, int xl = 0, int xr = N, int k = 0)
{
	if (ql >= xr || qr <= xl) return 0;
	if (ql <= xl && qr >= xr) return seg[k];
	int xm = (xl+xr)/2;
	shift(xl, xr, k);
	return get(ql, qr, xl, xm, 2*k+1) + get(ql, qr, xm, xr, 2*k+2);
}
int f(int ql, int qr, int val, int xl = 0, int xr = N, int k = 0)
{
	// first place betwen [ql, qr) > val;
	if (ql >= xr || qr <= xl || mx[k] <= val) return qr;
	if (xr - xl == 1)
	{
		if (mx[k] > val) return xl;
		return qr;
	}
	int xm = (xl + xr) / 2;
	shift(xl, xr, k);
	int p = f(ql, qr, val, xl, xm, 2*k+1);
	if (p != qr) return p;
	return f(ql, qr, val, xm, xr, 2*k+2);
}
inline void fix (int ql, int qr, int val)
{
	int pos = f(ql, qr, val);
	Set(ql, pos, val);
}
int tmp[N];
inline void initPS()
{
	memset(ps, 0, sizeof ps);
	memset(tmp, 0, sizeof tmp);
	for (auto x : div[a[0]])
		tmp[x]++;
	for (int i = 1; i < n; i++)
	{
		int res = 0;
		for (auto x : div[a[i]])
			if (tmp[x]++)
				res = x;
		ps[i] = max(ps[i-1], res);
	}
}
inline void init()
{
	initPS();
	for (int i = 0; i < n-1; i++)
		Set(i, i+1, ps[i]);
	reverse(a, a+n);
	initPS();
	reverse(ps, ps+n);
	reverse(a, a+n);
}
void print()
{
	cout << "\nprint: \n";
	for (int i = 0; i < n; i++)
		cout << get(i, i+1) << " ";
	cout << endl;
}
int main()
{
	scanf("%d", &n);
	for (int i = 0; i < n; i++) scanf("%d", &a[i]);
	makeL();
	divisor();
	init();
	ll ans = get(0, n-1);
	ans += ps[1];
	for (int i = n-1; i > 1; i--)
	{
		int val = a[i];
		int ql = 0, qr = i-1;
		fix(ql, qr, ps[i]);
		for (auto x : div[val])
			if (L[x] < qr)
				fix(L[x], qr, x);
		ans += get(ql, qr);
		ans += ps[i];
	}
	printf("%lld\n", ans);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (long long i = (long long)(a); i < (long long)(b); ++i)
#define ROF(i, a, b) for (long long i = (long long)(b) - 1; i >= (long long)(a); --i)
#define sz(x) (int((x).size()))
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<pair<int, int>> VPII;
template <typename A> inline std::istream& IN(A& a) { return std::cin >> a; }
template <typename A, typename ...Args> inline std::istream& IN(A& a, Args&... rest) { std::cin >> a; return IN(rest...); }
inline std::ostream& OUT() { return std::cout << std::endl; }
template <typename A> inline std::ostream& _OUT(const A& a) { return std::cout << a; }
template <typename A, typename...Args> inline std::ostream& _OUT(const A& a, const Args&... rest) { std::cout << a << " "; return _OUT(rest...); }
template <typename...Args> inline std::ostream& OUT_(const Args&... args) { _OUT(args...); return std::cout << " "; }
template <typename...Args> inline std::ostream& OUT(const Args&... args) { _OUT(args...); return std::cout << std::endl; }
#define INn(a, b, c)          { FOR(_i_, b, c) IN(a[_i_]); }
#define INnm(a, b, c, d, e)   { FOR(__i__, b, c) INn(a[__i__], d, e) }
#define OUTn(a, l, r)         { FOR(_i_, l, r - 1) OUT_((a)[_i_]); if(r > 0) OUT((a)[r - 1]); }
#define OUTnm(a, b, c, d, e)  { FOR(__i__, b, c) OUTn(a[__i__], d, e) }
template<typename T, typename U> inline bool cmax(T& a, const U& b) { return b > a ? a = b, true : false; }
template<typename T, typename U> inline bool cmin(T& a, const U& b) { return b < a ? a = b, true : false; }
//

const int _ = int(2e5 + 10);
long long n, N;
int a[_];
VI v[_];
int rb[_];
long long ans[_];

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

	IN(n);
	FOR(i, 1, n + 1) {
		IN(a[i]);
		cmax(N, a[i]);
		for (int d = 1; d * d <= a[i]; ++d) if (a[i] % d == 0) {
			v[d].push_back(i);
			int t = a[i] / d;
			if (d != t) v[t].push_back(i);
		}
		rb[i] = i;
	}
	ans[N] = n * (n + 1) / 2;

	ROF(i, 1, N) {
		ans[i] = ans[i + 1];
		if (sz(v[i + 1]) <= 1) continue;
		int newrb = n + 1;
		FOR(j, v[i + 1][1] + 1, n + 1) {
			if (rb[j] >= newrb) break;
			ans[i] -= newrb - rb[j];
			rb[j] = newrb;
		}
		newrb = v[i + 1].back();
		FOR(j, v[i + 1][0] + 1, v[i + 1][1] + 1) {
			if (rb[j] >= newrb) break;
			ans[i] -= newrb - rb[j];
			rb[j] = newrb;
		}
		newrb = v[i + 1][sz(v[i + 1]) - 2];
		FOR(j, 1, v[i + 1][0] + 1) {
			if (rb[j] >= newrb) break;
			ans[i] -= newrb - rb[j];
			rb[j] = newrb;
		}
	}

	if (rb[1] <= n - 1) ++ans[0];
	if (rb[1] <= n) ++ans[0];
	if (rb[2] <= n) ++ans[0];

/* 	OUT(n);
	OUTn(a, 1, n + 1);
	OUTn(rb, 1, n + 1);
	OUTn(ans, 0, N + 1); */

	long long ret = 0;
	FOR(i, 1, N + 1) {
		ret += (ans[i] - ans[i - 1]) * i;
	}
	OUT(ret);

	return 0;
}


#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<ctime>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define maxn 200005
#define ls o<<1
#define rs o<<1|1
struct sgt
{
	int l,r,mn,mm,tag;
	long long sum;
}c[maxn<<2];
int n;
long long ans;
int a[maxn];
long long h[maxn];
vector<int>x[maxn];
void pd(int o)
{
	if(c[o].tag)
	{
		c[ls].mm=c[ls].mn=c[o].tag;
		c[rs].mm=c[rs].mn=c[o].tag;
		c[ls].tag=c[rs].tag=c[o].tag;
		c[ls].sum=((long long)c[ls].r-c[ls].l+1)*c[o].tag;
		c[rs].sum=((long long)c[rs].r-c[rs].l+1)*c[o].tag;
		c[o].tag=0;
	}
}
void build(int l,int r,int o)
{
	c[o].l=l,c[o].r=r;
	if(l==r)
	{
		c[o].mn=c[o].sum=c[o].mm=l;
		return ;
	}
	int mid=(l+r)>>1;
	build(l,mid,ls);
	build(mid+1,r,rs);
	c[o].mm=max(c[ls].mm,c[rs].mm);
	c[o].mn=min(c[ls].mn,c[rs].mn);
	c[o].sum=c[ls].sum+c[rs].sum;
}
void update(int l,int r,int k,int o)
{
	if(l>r) return ;
	if(l<=c[o].l&&r>=c[o].r&&k<=c[o].mn) return ;
 	if(l<=c[o].l&&r>=c[o].r&&k>=c[o].mm)
	{
		c[o].tag=k;
		c[o].mm=c[o].mn=c[o].tag;
		c[o].sum=((long long)c[o].r-c[o].l+1)*k;
		return ;
	}
	pd(o);
	int mid=(c[o].l+c[o].r)>>1;
	if(l>mid) update(l,r,k,rs);
	else if(r<=mid) update(l,r,k,ls);
	else
	{
		update(l,mid,k,ls);
		update(mid+1,r,k,rs);
	}
	c[o].mm=max(c[ls].mm,c[rs].mm);
	c[o].mn=min(c[ls].mn,c[rs].mn);
	c[o].sum=c[ls].sum+c[rs].sum;
}
int main()
{
	scanf("%d",&n);
	h[0]=3;
	for(int i=1;i<=n;++i) scanf("%d",&a[i]);
	for(int i=1;i<=n;++i)
	{
		int t=sqrt(a[i]);
		for(int j=1;j<=t;++j)
		{
			if(a[i]%j==0)
			{
				x[j].push_back(i);
				if(j*j!=a[i]) x[a[i]/j].push_back(i);
			}
		}
	}
	/*for(int i=1;i<=5;++i)
	{
		for(int j=0;j<x[i].size();++j) cout<<x[i][j]<<" ";
		cout<<endl;
	}*/
	build(1,n,1);
	for(int i=200000;i>=1;--i)
	{
		h[i]=(long long)n*n-c[1].sum+n;
		if(x[i].size()<=1) continue;
		else
		{
			update(1,x[i][0],x[i][x[i].size()-2],1);
			update(x[i][0]+1,x[i][1],x[i][x[i].size()-1],1);
			update(x[i][1]+1,n,n+1,1);
		}
	}
	//for(int i=0;i<=5;++i) cout<<i<<"    "<<h[i]<<endl;
	for(int i=200000;i>=1;--i)
		ans=ans+(long long)i*(h[i]-h[i-1]);
	printf("%lld",ans);
	return 0;
}
//hellobig_tq


#include <bits/stdc++.h>
using namespace std;

const int N = (int)2e5;
typedef int arr[N + 10];
typedef long long ll;

int n, m, cnts;
arr a, ra;

struct segm {
	int l, r, d;
}s[3 * N + 10];

struct comp {
	bool operator () (const segm &a, const segm &b) { return a.d > b.d; }
};

ll cans;
set <segm, comp> ava;

void get_seg() {
	s[++cnts] = (segm){1, n, 1};
	for (int i = 2; i <= m; ++i) {
		int l1 = m + 1, l2 = m + 1, r1 = -1, r2 = -1;
		for (int j = i; j <= m; j += i) {
			int k = ra[j]; if (!k) continue;
			if (k < l1) l2 = l1, l1 = k; else if (k < l2) l2 = k;
			if (k > r2) r1 = r2, r2 = k; else if (k > r1) r1 = k;
		}
		if (l2 == m + 1 || r1 == -1) continue;
		if (l1 + 1 < r2) s[++cnts] = (segm){l1 + 1, r2 - 1, i};
		if (r1 > 1) s[++cnts] = (segm){1, r1 - 1, i};
		if (l2 < n) s[++cnts] = (segm){l2 + 1, n, i};
	}
}

bool cmp(const segm &a, const segm &b) { return (a.l < b.l) || (a.l == b.l && a.r < b.r); }

void insert(int st, segm ins) {
	if (ava.empty()) { cans += (ll)(ins.r - st + 1) * (ll)ins.d, ava.insert(ins); return; }
	set <segm, comp> :: iterator it = ava.lower_bound(ins), tmp;
	if (it == ava.end()) {
		--it;
		if (ins.r > (*it).r) cans += (ll)(ins.r - (*it).r) * (ll)ins.d, ava.insert(ins);
		return;
	}
	int lst = st - 1;
	if (it != ava.begin()) {
		--it;
		if (ins.r <= (*it).r) return;
		cans += (ll)ins.d * (ll)(ins.r - (*it).r);
		lst = (*it).r, ++it;
	}
	else cans += (ll)ins.d * (ll)(ins.r - st + 1);
	for ( ; it != ava.end() && (*it).r <= ins.r; ) {
		cans -= (ll)(*it).d * (ll)((*it).r - lst);
		tmp = it, lst = (*tmp).r, ++it, ava.erase(tmp);
	}
	if (it != ava.end()) {
		cans -= (ll)(*it).d * (ll)((*it).r - lst);
		cans += (ll)(*it).d * (ll)((*it).r - ins.r);
	}
	ava.insert(ins);
}

ll get_ans() {
	ll res = 0;
	sort(s + 1, s + cnts + 1, cmp);
	int cnt = 1;
	for (int i = 1; i <= n; ++i) {
		for ( ; cnt <= cnts && s[cnt].l == i; insert(i, s[cnt]), ++cnt);
		res += cans, cans -= (ll)(*ava.begin()).d;
		if ((*ava.begin()).r == i) ava.erase(ava.begin());
	}
	return res;
}

int main() {

	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) scanf("%d", a + i), ra[a[i]] = i, m = max(m, a[i]);
	if (n < 3) {
		if (n == 1) printf("0\n");
		else printf("%d\n", __gcd(a[1], a[2]));
		return 0;
	}

	get_seg();
	cout << get_ans() - 3 << endl;
	return 0;
}


//satyaki3794
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <cassert>
#include <cmath>
#define ff first
#define ss second
#define pb push_back
#define MOD (1000000007LL)
#define LEFT(n) (2*(n))
#define RIGHT(n) (2*(n)+1)

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;

ll pwr(ll base, ll p, ll mod = MOD){
ll ans = 1;while(p){if(p&1)ans=(ans*base)%mod;base=(base*base)%mod;p/=2;}return ans;
}

const int N = 200000;
int n, arr[N+5], pos[N+5];
vector<int> multiples[N+5];
ll cnt[N+5], minval[4*N+5], maxval[4*N+5], sumval[4*N+5], lazy[4*N+5];

void build(int node, int s, int e){
    if(s > e)   return;
    if(s == e){
        minval[node] = maxval[node] = sumval[node] = s;
        return;
    }
    int mid = (s+e)/2;
    build(LEFT(node), s, mid);
    build(RIGHT(node), mid+1, e);
    minval[node] = min(minval[LEFT(node)], minval[RIGHT(node)]);
    maxval[node] = max(maxval[LEFT(node)], maxval[RIGHT(node)]);
    sumval[node] = sumval[LEFT(node)] + sumval[RIGHT(node)];
}

int kth_query(int node, int s, int e, int threshold){
    if(minval[node] >= threshold)    return 0;
    if(s == e)  return s;
    int mid = (s+e)/2;
    if(minval[RIGHT(node)] < threshold)    return kth_query(RIGHT(node), mid+1, e, threshold);
    return kth_query(LEFT(node), s, mid, threshold);
}

void update(int node, int s, int e, int lo, int hi, ll val){
    if(s > e || lo > hi || val <= 0)   return;
    if(lazy[node] != 0){
        minval[node] = maxval[node] = lazy[node];
        sumval[node] = (e-s+1)*lazy[node];
        if(s != e){
            lazy[LEFT(node)] = lazy[RIGHT(node)] = lazy[node];
        }
        lazy[node] = 0;
    }
    if(lo > e || s > hi)    return;
    if(s >= lo && e <= hi){
        minval[node] = maxval[node] = val;
        sumval[node] = (e-s+1)*val;
        if(s != e){
            lazy[LEFT(node)] = lazy[RIGHT(node)] = val;
        }
        return;
    }
    int mid = (s+e)/2;
    update(LEFT(node), s, mid, lo, hi, val);
    update(RIGHT(node), mid+1, e, lo, hi, val);
    minval[node] = min(minval[LEFT(node)], minval[RIGHT(node)]);
    maxval[node] = max(maxval[LEFT(node)], maxval[RIGHT(node)]);
    sumval[node] = sumval[LEFT(node)] + sumval[RIGHT(node)];
}

ll sum_query(int node, int s, int e, int lo, int hi){
    if(s > e)   return 0;
    if(lazy[node] != 0){
        minval[node] = maxval[node] = lazy[node];
        sumval[node] = (e-s+1)*lazy[node];
        if(s != e){
            lazy[LEFT(node)] = lazy[RIGHT(node)] = lazy[node];
        }
        lazy[node] = 0;
    }
    if(lo > e || s > hi)    return 0;
    if(s >= lo && e <= hi)  return sumval[node];
    int mid = (s+e)/2;
    return sum_query(LEFT(node), s, mid, lo, hi) + sum_query(RIGHT(node), mid+1, e, lo, hi);
}

int main(){

    // ios_base::sync_with_stdio(0);
    // freopen("input.txt", "r", stdin);

    scanf("%d", &n);
    for(int i=1;i<=n;i++){
        scanf("%d", &arr[i]);
        pos[arr[i]] = i;
    }

    if(n <= 2){
        printf("0\n");
        return 0;
    }

    for(int i=1;i<=N;i++)
        for(int j=i;j<=N;j+=i)
            if(pos[j] > 0)
                multiples[i].pb(pos[j]);
    for(int i=1;i<=N;i++)
        sort(multiples[i].begin(), multiples[i].end());

    build(1, 1, n);
    cnt[N+1] = 1LL*n*(n+1) - sum_query(1, 1, n, 1, n);
    for(int i=N;i>=1;i--){

        if((int)multiples[i].size() < 2){
            cnt[i] = cnt[i+1];
            continue;
        }

// cout<<"now at i = "<<i<<endl;

        int k = multiples[i].size();

        int temp = kth_query(1, 1, n, multiples[i][k-2]);
        int l = 1, r = min(multiples[i][0], temp);
// cout<<"updated range "<<l<<" "<<r<<" with "<<multiples[i][k-2]<<" coz temp = "<<temp<<endl;
        update(1, 1, n, l, temp, multiples[i][k-2]);

        temp = kth_query(1, 1, n, multiples[i][k-1]);
        l = multiples[i][0]+1;    r = min(multiples[i][1], temp);
// cout<<"updated range "<<l<<" "<<r<<" with "<<multiples[i][k-1]<<" coz temp = "<<temp<<endl;
        update(1, 1, n, l, temp, multiples[i][k-1]);

        temp = kth_query(1, 1, n, n+1);
        l = multiples[i][1]+1;    r = min(n, temp);
// cout<<"updated range "<<l<<" "<<r<<" with "<<n+1<<" coz temp = "<<temp<<endl;
        update(1, 1, n, l, temp, n+1);

        cnt[i] = 1LL*n*(n+1) - sum_query(1, 1, n, 1, n);
    }

    ll ans = 0;
    // cnt[1] = 3; //the intervals [1..n], [2..n] and [1..n-1]
    for(int i=N;i>=1;i--)
        ans += 1LL*i*(cnt[i+1]-cnt[i]);
    printf("%lld\n", ans);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PI;
int mn[200010*4],ch[200010*4];
ll sum[200010*4];
inline void down(int l,int r,int idx){
	if(ch[idx]!=-1){
		int mid=(l+r)>>1;
		mn[idx<<1|1]=mn[idx<<1]=ch[idx<<1]=ch[idx<<1|1]=ch[idx];
		sum[idx<<1]=(ll)(mid-l+1)*ch[idx];
		sum[idx<<1|1]=(ll)(r-mid)*ch[idx];
		ch[idx]=-1;
	}
}
void modify(int l,int r,int ql,int qr,int v,int idx){
	if(ql>qr) return;
	if(l==ql && r==qr){
		ch[idx]=mn[idx]=v;
		sum[idx]=(ll)v*(r-l+1);
	}else{
		int mid=(l+r)>>1;
		down(l,r,idx);
		if(qr<=mid) modify(l,mid,ql,qr,v,idx<<1);
		else if(ql>mid) modify(mid+1,r,ql,qr,v,idx<<1|1);
		else{
			modify(l,mid,ql,mid,v,idx<<1);
			modify(mid+1,r,mid+1,qr,v,idx<<1|1);
		}
		sum[idx]=sum[idx<<1]+sum[idx<<1|1];
		mn[idx]=min(mn[idx<<1],mn[idx<<1|1]);
	}
}
int find_left(int l,int r,int v,int idx){
	if(l==r){
		if(mn[idx]<v) return l;
		return -1;
	}
	down(l,r,idx);
	int mid=(l+r)>>1;
	if(mn[idx<<1]<v) return find_left(l,mid,v,idx<<1);
	return find_left(mid+1,r,v,idx<<1|1);
}
ll query(int l,int r,int ql,int qr,int idx){
	if(l==ql && r==qr) return sum[idx];
	int mid=(l+r)>>1;
	down(l,r,idx);
	if(qr<=mid) return query(l,mid,ql,qr,idx<<1);
	else if(ql>mid) return query(mid+1,r,ql,qr,idx<<1|1);
	return query(l,mid,ql,mid,idx<<1)+query(mid+1,r,mid+1,qr,idx<<1|1);
}
inline void getFactor(vector<int>& fac,int x){
	for(int i=1;(ll)i*i<=x;i++){
		if(x%i==0){
			fac.push_back(i);
			if(x/i!=i)
				fac.push_back(x/i);
		}
	}
}
int a[200010];
vector<int> fac[200010];
deque<int> idx[200010];
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",a+i);
		if(fac[a[i]].size()==0) getFactor(fac[a[i]],a[i]);
		for(int& x:fac[a[i]])
			idx[x].push_back(i);
	}
	memset(ch,-1,sizeof ch);
	for(int x=1;x<=200000;x++){
		if(idx[x].size()>=2){
			int Left=find_left(1,n,x,1);
			modify(1,n,Left,idx[x][idx[x].size()-2]-1,x,1);
		}
	}
	ll ans=0;
	for(int i=1;i<=n;i++){
		ans+=query(1,n,i,n,1);
		for(int& x:fac[a[i]]){
			idx[x].pop_front();
			idx[x].push_back(i+n);
			if(idx[x].size()>=2){
				int Left=find_left(1,n,x,1);
				if(Left!=-1){
					modify(1,n,Left,min(idx[x][idx[x].size()-2]-1,n),x,1);
				}
			}
		}
	}
	printf("%lld\n",ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N = 2e5+7;
#define div Div
vector<int> div[N];
int L[N], a[N], ps[N], toset[4*N], n;
typedef long long ll;
ll seg[4*N], mx[4*N];
inline void makeL()
{
	for (int i = 0; i < N; i++) L[i] = n;
	for (int i = 0; i < n; i++)
		L[a[i]] = min(L[a[i]], i);
	L[1] = 0;
	for (int i = 2; i < N; i++)
		for (int j = i; j < N; j += i)
			L[i] = min(L[i], L[j]);
}
inline void divisor()
{
	for (int i = 1; i < N; i++)
	{
		for (int j = i; j < N; j += i)
			div[j].push_back(i);
		div[i].shrink_to_fit();
	}
}
inline void fix (int xl, int xr, int k, int val)
{
	toset[k] = mx[k] = val;
	seg[k] = 1ll * (xr - xl) * val;
}
inline void shift(int xl, int xr, int k)
{
	if (toset[k] == -1) return;
	int val = toset[k];
	toset[k] = -1;
	int xm = (xl+xr) / 2;
	fix(xl, xm, 2*k+1, val);
	fix(xm, xr, 2*k+2, val);
}
void Set(int ql, int qr, int val, int xl = 0, int xr = N, int k = 0)
{
	if (ql >= xr || qr <= xl) return;
	if (ql <= xl && qr >= xr)
	{
		fix(xl, xr, k, val);
		return;
	}
	shift(xl, xr, k);
	int xm = (xl+xr) / 2;
	Set(ql, qr, val, xl, xm, 2*k+1);
	Set(ql, qr, val, xm, xr, 2*k+2);
	seg[k] = seg[2*k+1] + seg[2*k+2];
	mx[k] = max(mx[2*k+1], mx[2*k+2]);
}
ll get (int ql, int qr, int xl = 0, int xr = N, int k = 0)
{
	if (ql >= xr || qr <= xl) return 0;
	if (ql <= xl && qr >= xr) return seg[k];
	int xm = (xl+xr)/2;
	shift(xl, xr, k);
	return get(ql, qr, xl, xm, 2*k+1) + get(ql, qr, xm, xr, 2*k+2);
}
int f(int ql, int qr, int val, int xl = 0, int xr = N, int k = 0)
{
	// first place betwen [ql, qr) > val;
	//cout << ql << " " << qr << " " << val << " " << xl << " " << xr << " " << mx[k] << endl;
	if (ql >= xr || qr <= xl || mx[k] <= val) return qr;
	if (xr - xl == 1)
	{
		if (mx[k] > val) return xl;
		return qr;
	}
	int xm = (xl + xr) / 2;
	shift(xl, xr, k);
	int p = f(ql, qr, val, xl, xm, 2*k+1);
	if (p != qr) return p;
	return f(ql, qr, val, xm, xr, 2*k+2);
}

int f2(int ql, int qr, int val)
{
	int l = ql - 1, r = qr;
	while (r-l > 1)
	{
		int m = (l+r) / 2, x = get(m, m+1);
		if (x > val) r = m;
		else l = m;
	}
	return r;
}
inline void fix (int ql, int qr, int val)
{
	int pos = f(ql, qr, val);
	Set(ql, pos, val);
}
int tmp[N];
inline void initPS()
{
	memset(ps, 0, sizeof ps);
	memset(tmp, 0, sizeof tmp);
	for (auto x : div[a[0]])
		tmp[x]++;
	for (int i = 1; i < n; i++)
	{
		int res = 0;
		for (auto x : div[a[i]])
			if (tmp[x]++)
				res = x;
		ps[i] = max(ps[i-1], res);
	}
}
inline void init()
{
	initPS();
	for (int i = 0; i < n-1; i++)
		Set(i, i+1, ps[i]);
	reverse(a, a+n);
	initPS();
	reverse(ps, ps+n);
	reverse(a, a+n);
}
void print()
{
	return;
	cout << "\nprint: \n";
	for (int i = 0; i < n; i++)
		cout << get(i, i+1) << " ";
	cout << endl;
}
int main()
{
	//ios::sync_with_stdio(0);
	//cin >> n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) scanf("%d", &a[i]);
	makeL();
	divisor();
	init();
	ll ans = get(0, n-1);
	ans += ps[1];
	for (int i = n-1; i > 1; i--)
	{
		int val = a[i];
		int ql = 0, qr = i-1;
		fix(ql, qr, ps[i]);
		for (auto x : div[val])
			if (L[x] < qr)
				fix(L[x], qr, x);
		ans += get(ql, qr);
		ans += ps[i];
	}
	print();
	printf("%lld\n", ans);
	//cout << ans << endl;
	return 0;
}


#include <functional>
#include <algorithm>
#include <iostream>
#include <memory.h>
#include <sstream>
#include <assert.h>
#include <fstream>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstdio>
#include <complex>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <set>
#include <map>
#include <map>

using namespace std;

const int N = 200002;
const int sizeTree = (1 << 20);

int tAdd[sizeTree], mn[sizeTree], mx[sizeTree];
long long tSum[sizeTree];
int n;
int a[N];
pair < int, int > b[N], c[N];
long long ans[N];

void push(int v, int tl, int tr)
{
	if (tAdd[v] != 0)
	{
		int tm = (tl + tr) / 2;
		tAdd[2 * v] = mn[2 * v] = mx[2 * v] = tAdd[v];
		tAdd[2 * v + 1] = mn[2 * v + 1] = mx[2 * v + 1] = tAdd[v];
		tSum[2 * v] = 1ll * (tm - tl + 1) * tAdd[v];
		tSum[2 * v + 1] = 1ll * (tr - tm) * tAdd[v];
		tAdd[v] = 0;
	}
}

void build(int v, int tl, int tr)
{
	if (tl == tr)
	{
		tAdd[v] = 0;
		tSum[v] = tl;
		mn[v] = mx[v] = tl;
		return;
	}
	int tm = (tl + tr) / 2;
	build(2 * v, tl, tm);
	build(2 * v + 1, tm + 1, tr);
	tSum[v] = tSum[2 * v] + tSum[2 * v + 1];
	mn[v] = min(mn[2 * v], mn[2 * v + 1]);
	mx[v] = max(mx[2 * v], mx[2 * v + 1]);
}

void assign(int v, int tl, int tr, int l, int r, int value)
{
	if (l > r || mn[v] >= value)
		return;
	if (tl == l && tr == r && mx[v] <= value)
	{
		mx[v] = mn[v] = tAdd[v] = value;
		tSum[v] = 1ll * (tr - tl + 1) * value;
		return;
	}
	push(v, tl, tr);
	int tm = (tl + tr) / 2;
	assign(2 * v, tl, tm, l, min(r, tm), value);
	assign(2 * v + 1, tm + 1, tr, max(l, tm + 1), r, value);
	tSum[v] = tSum[2 * v] + tSum[2 * v + 1];
	mn[v] = min(mn[2 * v], mn[2 * v + 1]);
	mx[v] = max(mx[2 * v], mx[2 * v + 1]);
}

void update(int j, int pos)
{
	if (b[j].first == -1)
		b[j].first = pos;
	else if (b[j].second == -1)
		b[j].second = pos;
	c[j].first = c[j].second;
	c[j].second = pos;
}

int main()
{
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
	memset(b, -1, sizeof(b));
	memset(c, -1, sizeof(c));
	scanf("%d", &n);
	for (int i = 0; i < n; ++i)
		scanf("%d", &a[i]);
	build(1, 0, n - 1);
	for (int i = 0; i < n; ++i)
	{
		for (int j = 1; j * j <= a[i]; ++j)
		{
			if (a[i] % j == 0)
			{
				update(j, i);
				if (a[i] / j != j)
					update(a[i] / j, i);
			}
		}
	}
	ans[0] = (n == 1 ? 1 : 3);
	for (int i = N - 1; i >= 1; --i)
	{
		ans[i] = 1ll * n * n - tSum[1];
		if (b[i].first != c[i].second)
		{
			assign(1, 0, n - 1, b[i].second + 1, n - 1, n);
			assign(1, 0, n - 1, b[i].first + 1, b[i].second, c[i].second);
			assign(1, 0, n - 1, 0, b[i].first, c[i].first);
		}

	}
	long long res = 0;
	for (int i = 1; i < N; ++i)
	{
		res += 1ll * (ans[i] - ans[i - 1]) * i;
	}
	cout << res << endl;
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
typedef long long ll;
ll h[200005];
ll mat[200005];
ll c[200005 << 2];
ll a[200005 << 2];
ll lz[200005 << 2];
vector<ll> v[200005];

ll u;
int yl,yr;
void build(ll o,ll l,ll r)
{
    int rt = o;
    if(l==r){
        a[rt]=c[rt]=1ll*l;
        return;
    }
    int m=(l+r)>>1;
    build(rt<<1,l,m);
    build(rt<<1|1,m+1,r);
    c[rt]=c[rt<<1]+c[rt<<1|1];
    a[rt]=min(a[rt<<1],a[rt<<1|1]);
}

void down(ll o,ll l,ll r)
{
    ll rt = o;
   if(!lz[rt])return;
   int m=(l+r)>>1;
   c[rt<<1]=1ll*lz[rt]*(m-l+1);
   c[rt<<1|1]=1ll*lz[rt]*(r-m);
   a[rt<<1]=a[rt<<1|1]=a[rt];
   lz[rt<<1]=lz[rt<<1|1]=lz[rt];
   lz[rt]=0;
}

void modify(ll o,ll l,ll r)
{
    ll rt = o;ll x = yl;ll y = yr;
    ll tmp = u;
//    if(yl <= l && yr >= r){
//        c[o] = 1LL * u *(r - l + 1);
//        s[o] = u;
//        lz[o] = u;return;
//    }
//    pushdown(o,l,r);
//    int m = (l + r) >> 1;
//    if(yl <= m)update(o*2,l,m);
//    if(yr > m) update(o*2+1 , m+1,r);
//    c[o] = c[o*2] + c[o*2+1];
//    s[o] = min(s[o*2],s[o*2+1]);
//    if(lz[o*2] == lz[o*2+1] && lz[o*2] >= 0)lz[o] = lz[o*2];

   if(x<=l&&r<=y){
     c[rt]=1ll*tmp*(r-l+1);
     a[rt]=lz[rt]=tmp;
     return;
   }
   down(rt,l,r);
   int m=(l+r)>>1;
   if(x<=m)modify(rt<<1,l,m);
   if(y>m)modify(rt<<1|1,m+1,r);
   c[rt]=c[rt<<1]+c[rt<<1|1];
   a[rt]=min(a[rt<<1],a[rt<<1|1]);
}

ll ask(ll o,ll l,ll r)
{
//    if(l == r && c[o] < u )return l;
//    if(l == r && c[o] >=u )return 0;
//    if(lz[o]!=-1 && lz[o] < u)return r;
//    if(lz[o] != -1 && lz[o] >= u)return 0;
//    int mid = (l+r)>>1;
//    if(s[o*2+1] < u)return query(o*2+1,mid+1,r);
//    else return query(o*2,l,mid);
    ll rt = o;ll k = u;
    if(l==r)return l;
    int m=(l+r)>>1;
    if(a[rt<<1|1]<k)return ask(rt<<1|1,m+1,r);
    else return ask(rt<<1,l,m);
}

int main()
{
//    freopen("data.txt","r",stdin);
    int n;
    scanf("%d",&n);
    ll mx = -1;
    memset(a,0,sizeof(a));
    for(int i = 1; i < n+1 ; ++i){
        ll x;
        scanf("%I64d",&x);
        mat[x] = i;
        mx = max(mx,x);
    }
    for(int i = 1; i <=mx; ++i){
        for(int j = 1;j*i<=mx;++j){
            if(mat[j*i])
                v[i].push_back(mat[j*i]);
        }
    }
    for(int i = 0; i <= mx;++i)sort(v[i].begin(),v[i].end());
    ll sum =1LL * n * (n+1);
    build(1,1,n);
    for(int i = mx; i >= 0; --i){
        h[i] = sum - c[1];
        ll k = v[i].size();
        if(k < 2){continue;}
        u = n + 1;
        yl = v[i][1]+1;yr = n;
        if(yl <= yr)
            modify(1,1,n);

        u = v[i][k-1];
//        int pos = query(1,1,n);
//        pos = min(pos , v[i][1]);
//        if(pos > v[i][0] && pos <= v[i][1]){
//            yl = v[i][0] + 1;yr = pos;
//            update(1,1,n);
//        }
        if(a[1] < u){
            ll pos = ask(1,1,n);
            pos = min(pos,v[i][1]);
            if(pos > v[i][0]){
                yl = v[i][0] + 1;yr = pos;
                modify(1,1,n);
            }
        }

        u = v[i][k-2];
//        pos = query(1,1,n);
//        pos = min(pos , v[i][0]);
//        if(pos >= 1 && pos <= v[i][0]){
//            yl = 1;yr = pos;
//            update(1,1,n);
//        }
        if(a[1] < u){
            ll pos = ask(1,1,n);
            pos = min(pos,v[i][0]);
            yl = 1;yr = pos;
            if(pos > 0)modify(1,1,n);
        }
    }
    ll ans = 0;
    for(int i = 1 ;i <= mx; ++i){
        ans += 1LL * i * (h[i] - h[i-1]);
    }
    printf("%I64d\n",ans);
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <climits>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string>
#include <list>
#include <bitset>
#include <vector>
using namespace std;

#define I64d_OJ

#ifdef I64d_OJ
#define LL __int64
#endif // I64d_OJ
//#ifdef I64d_OJ
//#define LL long long
//#endif // I64d_OJ

typedef unsigned LL ULL;
typedef unsigned uint;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef pair<LL,LL> pLL;
typedef vector<int> vi;

inline LL read(){
    LL x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-f; ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}

#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define ls rt<<1
#define rs rt<<1|1
#define MID(a,b) (((LL)(a)+(LL)(b))>>1)
#define absx(a) ((a)<0?-(a):(a))
#define MK(a,b) make_pair(a,b)
#define PB(a) push_back(a)
#define lowbit(x) ((x)&-(x))

template< typename T >
inline void Max(T &a,T &b){if(a<b) a=b;}
template< typename T>
inline void Min(T &a,T &b){if(a>b) a=b;}

const double pi=(double)acos(-1.0);
const double eps=(double)1e-10;
const int INF = (int) 0x3f3f3f3f;
const int MOD = (int) 1e9+7;
const int MAXN =(int) 2e5+10;
const int MAXM = (int) 1e5+10;

///--------------------START-------------------------
int n;
vi G[MAXN];
LL A[MAXN];
LL sum[MAXN<<2];
LL mi[MAXN<<2],mx[MAXN<<2],mark[MAXN<<2];
const int UP = (int) 2e5;

void Push_up(int rt){
    sum[rt]=sum[ls]+sum[rs];
    mx[rt]=max(mx[ls],mx[rs]);
    mi[rt]=min(mi[ls],mi[rs]);
}

void build(int l,int r,int rt){
    mark[rt]=0;
    if(l==r){
        mi[rt]=mx[rt]=sum[rt]=l;
        return;
    }
    int mid=(l+r)>>1;
    build(lson);
    build(rson);
    Push_up(rt);
}

void Push_down(int len,int rt){
    if(!mark[rt]) return;
    mark[ls]=mark[rs]=mark[rt];
    mx[ls]=mx[rs]=mark[rt];
    mi[ls]=mi[rs]=mark[rt];
    sum[ls]=mark[rt]*(len-(len>>1));
    sum[rs]=mark[rt]*(len>>1);
    mark[rt]=0;
}

void Maintain(int v,int l,int r,int rt){
    if(v<=mi[rt]) return;
    if(v>mx[rt]){
        mi[rt]=mx[rt]=mark[rt]=v;
        sum[rt]=(LL)v*(r-l+1);
        return;
    }
    Push_down(r-l+1,rt);
    int mid=(l+r)>>1;
    Maintain(v,lson);
    Maintain(v,rson);
    Push_up(rt);
}

int __ul,__ur,__uv;
void update(int l,int r,int rt){
    if(__ul<=l&&r<=__ur){
        Maintain(__uv,l,r,rt);
        return;
    }
    Push_down(r-l+1,rt);
    int mid=(l+r)>>1;
    if(__ul<=mid) update(lson);
    if(__ur>mid) update(rson);
    Push_up(rt);
}

void work(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        int x; scanf("%d",&x);
        for(int j=1;j*j<=x;j++){
            if(x%j==0){
                G[j].PB(i);
                if(j*j!=x) G[x/j].PB(i);
            }
        }
    }
    build(1,n,1);
    for(int i=UP;i>=0;i--){
        A[i]=(LL)n*(n+1)-sum[1];
//        if(i<=10) printf("i = %d , sum[1] = %I64d\n",i,sum[1]);
        int k=G[i].size();
        if(k>=2){
            __ul=1,__ur=G[i][0],__uv=G[i][k-2];
            update(1,n,1);
            __ul=G[i][0]+1,__ur=G[i][1],__uv=G[i][k-1];
            update(1,n,1);
            __ul=G[i][1]+1,__ur=n,__uv=n+1;
            if(__ul<=__ur) update(1,n,1);
        }
    }
    LL ans=0;
//    for(int i=1;i<=6;i++) printf("A[%d] = %I64d\n",i,A[i]);
    for(int i=1;i<=UP;i++){
        ans+=(A[i]-A[i-1])*i;
    }
    printf("%I64d\n",ans);
}

///--------------------END-------------------------
int main(){
#ifdef NNever
///freopen("data.in","r",stdin);
///freopen("out.txt","w",stdout);
#endif // NNever
    work();
    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <climits>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string>
#include <list>
#include <bitset>
#include <vector>
using namespace std;

#define I64d_OJ

#ifdef I64d_OJ
#define LL __int64
#endif // I64d_OJ
//#ifdef I64d_OJ
//#define LL long long
//#endif // I64d_OJ

typedef unsigned LL ULL;
typedef unsigned uint;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef pair<LL,LL> pLL;
typedef vector<int> vi;

inline LL read(){
    LL x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-f; ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}

#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define ls rt<<1
#define rs rt<<1|1
#define MID(a,b) (((LL)(a)+(LL)(b))>>1)
#define absx(a) ((a)<0?-(a):(a))
#define MK(a,b) make_pair(a,b)
#define PB(a) push_back(a)
#define lowbit(x) ((x)&-(x))

template< typename T >
inline void Max(T &a,T &b){if(a<b) a=b;}
template< typename T>
inline void Min(T &a,T &b){if(a>b) a=b;}

const double pi=(double)acos(-1.0);
const double eps=(double)1e-10;
const int INF = (int) 0x7fffffff;
const int MOD = (int) 1e9+7;
const int MAXN =(int) 2e5+10;
const int MAXM = (int) 1e5+10;

///--------------------START-------------------------
int n;
const int UP=30;
bool vis[MAXN];
vi G[MAXN];
LL A[MAXN];
int a[MAXN];
LL sum[MAXN<<2];
LL mx[MAXN<<2],mi[MAXN<<2],mark[MAXN<<2];
LL L1[MAXN],L2[MAXN],R1[MAXN],R2[MAXN];

void Push_up(int rt){
    mx[rt]=max(mx[ls],mx[rs]);
    mi[rt]=min(mi[ls],mi[rs]);
    sum[rt]=sum[ls]+sum[rs];
}

void build(int l,int r,int rt){
    mark[rt]=0;
    if(l==r){
        mx[rt]=mi[rt]=sum[rt]=l;
        return;
    }
    int mid=(l+r)>>1;
    build(lson);
    build(rson);
    Push_up(rt);
}

void Push_down(int len,int rt){
    if(!mark[rt]) return;
    mark[ls]=mark[rs]=mark[rt];
    mx[ls]=mx[rs]=mark[rt];
    mi[ls]=mi[rs]=mark[rt];
    sum[ls]=mark[rt]*(len-(len>>1));
    sum[rs]=mark[rt]*(len>>1);
    mark[rt]=0;
}

void Maintain(LL val,int l,int r,int rt){
    if(val<=mi[rt]) return;
    if(mx[rt]<val){
        sum[rt]=val*(r-l+1);
        mx[rt]=mi[rt]=mark[rt]=val;
        return;
    }
//    if(l==r){
//        sum[rt]=val;
//        mx[rt]=mi[rt]=mark[rt]=val;
//        return;
//    }
    Push_down(r-l+1,rt);
    int mid=(l+r)>>1;
    Maintain(val,lson);
    Maintain(val,rson);
    Push_up(rt);
}

int __ul,__ur,__uv;
void update(int l,int r,int rt){
    ///if(__uv<=mi[rt]) return;
    if(__ul<=l&&r<=__ur){
        Maintain(__uv,l,r,rt);
        return;
    }
    Push_down(r-l+1,rt);
    int mid=(l+r)>>1;
    if(__ul<=mid) update(lson);
    if(__ur>mid) update(rson);
    Push_up(rt);
}

void work(){
    cin>>n;
    for(int i=1 ; i<=n ; i++){
      scanf("%d",a+i);

      int x = sqrt(a[i]);

      for(int j=1 ; j<=x ; j++)
         if(a[i]%j == 0){
            if(!L1[j])
               L1[j] = i;
            else if(!L2[j]){
               L2[j] = i;
            }
            R2[j] = R1[j];
            R1[j] = i;

            if(j*j!=a[i]){

               if(!L1[a[i]/j])
                  L1[a[i]/j] = i;
               else if(!L2[a[i]/j]){
                  L2[a[i]/j] = i;
               }
               R2[a[i]/j] = R1[a[i]/j];
               R1[a[i]/j] = i;
            }
         }
   }

   for(int i=1 ; i<=n ; i++){
        __ul=__ur=__uv=i;
      update(1,n,1);
   }

   for(int i=2e5+1 ; i>=1 ; i--){
      if(L1[i] != R1[i]){
         __ul=1,__ur=L1[i],__uv=R2[i];
         update(1,n,1);
         __ul=L1[i]+1,__ur=L2[i],__uv=R1[i];
         update(1,n,1);
         __ul=L2[i]+1,__ur=n,__uv=n+1;
         update(1,n,1);
      }
      A[i] = (LL)n*(n+1) - sum[1];
   }

   LL ans = 0;

   for(int i=1 ; i<=2e5 ; i++)
      ans += (A[i+1]-A[i])*i;

   cout << ans << endl;
}

///--------------------END-------------------------
int main(){
#ifdef NNever
freopen("data.in","r",stdin);
///freopen("out.txt","w",stdout);
#endif // NNever
    work();
    return 0;
}


#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#define lson l, mid, x<<1
#define rson mid+1, r, x<<1|1
using namespace std;
const int maxn=300005;
typedef __int64 ll;
struct node
{
    int ma;
    int mi;
    ll sum;
    int lazy;
    int l, r;
}tree[maxn*4];

ll getsum(int x)
{
    if( tree[x].lazy ) return 1LL*(tree[x].r-tree[x].l+1)*tree[x].lazy;
    else return tree[x].sum;
}

int getmax( int x )
{
    if( tree[x].lazy ) return tree[x].lazy;
    else return tree[x].ma;
}

int getmin( int x )
{
    if( tree[x].lazy ) return tree[x].lazy;
    else return tree[x].mi;
}

void pushup( int x )
{
    tree[x].sum = getsum( x << 1 ) + getsum( x << 1 | 1 );
    tree[x].ma = max( getmax(x<<1), getmax(x<<1|1) );
    tree[x].mi = min( getmin(x<<1), getmin(x<<1|1) );
}

void pushdown( int x )
{
    if( tree[x].lazy ){
        tree[x<<1].lazy = tree[x<<1|1].lazy = tree[x].lazy;
        tree[x].mi = tree[x].ma = tree[x].lazy;
        tree[x].sum = (ll)tree[x].lazy*(tree[x].r-tree[x].l+1);
        tree[x].lazy = 0;
    }
}

void build( int l, int r, int x )
{
    tree[x].l = l;tree[x].r = r;tree[x].lazy = 0;
    if( l == r ){
        tree[x].sum = tree[x].mi = tree[x].ma = l;
        return;
    }
    int mid = (l+r)>>1;
    build( lson );
    build( rson );
    pushup(x);
}

void update( int L, int R, int val, int l, int r, int x )
{
    if( R < L ) return;
    pushdown(x);// 在对区间做任何修改之前，先pushdown
    if( tree[x].mi >= val ){
        return ;
    }
    int mid = (l+r) >> 1;
    if( L == l && R == r ){
        if( tree[x].ma <= val ){
            tree[x].lazy = val;
            return ;
        }
        else{
            update( L, mid, val, lson );
            update( mid+1, R, val, rson );
            pushup(x);
            return ;
        }
    }
    if( R <= mid ) update( L, R, val, lson );
    else if( L > mid ) update( L, R, val, rson );
    else{
        update( L, mid, val, lson );
        update( mid+1, R, val, rson );
    }
    pushup(x);
}

int pos[maxn];
ll h[maxn];
vector<int>p;

int main()
{
    int i, j, n, m, x;
    scanf("%d", &n);
    for( i = 1; i <= n; i ++ ){
        scanf("%d", &x);
        pos[x] = i;
    }
    build( 1, n, 1 );
    for( i = maxn-2; i >= 1; i -- ){
        p.clear();
        for( j = i+1; j < maxn; j += i+1 ){
            if( pos[j] ){
                p.push_back(pos[j]);
            }
        }
        sort( p.begin(), p.end() );
        int t = p.size();
        if( t > 1 ){
            update( 1, p[0], p[t-2], 1, n, 1 );
            update( p[0]+1, p[1], p[t-1], 1, n, 1 );
            update( p[1]+1, n, n+1, 1, n, 1 );
//            printf("id%d %d %d %d\n", i, 1,p[0],p[t-2]);
//            printf("id%d %d %d %d\n", i, p[0]+1,p[1],p[t-1]);
//            printf("id%d %d %d %d\n", i, p[1]+1,n,n+1);
        }
        h[i] = 1LL*n*(n+1)-getsum(1);
    }
    h[0] = 3;
    ll ans = 0;
    for( i = 1; i <= maxn-2; i ++ ){
        //printf("%d %I64d %I64d\n", i, h[i], ans);
        if( h[i]-h[i-1] >= 0 ) ans += 1LL*i*(h[i]-h[i-1]);
    }
    printf("%I64d\n", ans);
}


// 2011_2.cpp : Defines the entry point for the console application.
//

#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <iostream>
#include <memory.h>
#include <assert.h>
#include <functional>
#include <vector>
#include <string>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <deque>
#include <math.h>
#include <intrin.h>
#include <bitset>
#include <list>

using namespace std;

FILE * in, *out;

#define fo(a,b,c) for(int a = ( b ); a < ( c ); ++ a )
#define fr(a,b) fo( a, 0, ( b ) )
#define fi(a) fr( i, ( a ) )
#define fj(a) fr( j, ( a ) )
#define fk(a) fr( k, ( a ) )
#define mp make_pair
#define pb push_back
#define all(v) (v).begin( ), (v).end( )
#define _(a,b) memset( a, b, sizeof( a ) )

#define LL long long

int ri() { int a; fscanf(in, "%d", &a); return a; }
double rf() { double a; fscanf(in, "%lf", &a); return a; }
char sbuf[100005];
string rstr()
{
	//fscanf(in, "%lf", sbuf);
	char c;
	char * b = sbuf;
	while (c = fgetc(in))
	{
		if (c == '\n' || c == 255) break;
		*b++ = c;
	}
	*b = 0;
	return sbuf;
}

int nod(int a, int b)
{
	if (a == 1 || b == 1) return 1;
	if (a == 0) return b;
	if (b == 0) return a;

	return nod(b%a, a);
}

vector<int> primes;
void calculatePrimes()
{
	primes.push_back(2);
	for (int i = 3; i < 500; i += 2)
	{
		bool bFound = false;
		int m = (int)sqrt((float)i);
		for (int j = 1; j < primes.size() && !bFound && primes[j] <= m; j++)
			bFound = ((i%primes[j]) == 0);
		if (!bFound)
			primes.push_back(i);
	}
}

void fillMap(map<int, int> & pr, map<int, vector<int>> & pos, int i, map<int, int>::iterator j, int cur)
{
	if (j == pr.end())
	{
		if (pos[cur].size() == 0 || pos[cur].back() != i)
		{
			if (pos[cur].size() < 4)
				pos[cur].push_back(i);
			else
			{
				pos[cur][pos[cur].size() - 2] = pos[cur].back();
				pos[cur][pos[cur].size() - 1] = i;
			}
		}
		return;
	}

	int mult = 1;
	int second = j->second;
	int first = j->first;
	j++;

	for (int k = 0; k <= second; k++)
	{
		fillMap(pr, pos, i, j, cur*mult);
		mult *= first;
	}
}

long long insertSegment(int from, int to, set<pair<pair<int,int>,int>> & fills)
{
	long long ar = 0;
	int st = 0;
	if (from == to) return st;
	int line = from;
	set<pair<pair<int, int>, int>>::iterator start = fills.lower_bound(mp(mp(from, to), 0));
	if (start != fills.begin()) start--;

	set<pair<pair<int, int>, int>>::iterator end = fills.upper_bound(mp(mp(to, to), 0));
	for (set<pair<pair<int, int>, int>>::iterator i = start; i != end; )
	{
		if (i->first.second >= from)
		{
			long long next = min(i->first.second, to);
			long long f = max(i->first.first, from);
			if (i->second == -1 || i->second > line)
			{
				int save = i->second;
				int end = i->first.second;
				int beg = i->first.first;
				ar += (i->second == -1)?(f + next + 1 - 2*line)*(next - f) / 2:(i->second - line)*(next - f);
				i = fills.erase(i);
				if (to == end)
				{
					if (beg < from)
						fills.insert(mp(mp(beg, from), save));
					fills.insert(mp(mp(from, to), line));
					return ar;
				}
				else if (end < to)
				{
					if (beg < from)
						fills.insert(mp(mp(beg, from), save));
				}
				else
				{
					if (beg < from)
						fills.insert(mp(mp(beg, from), save));
					fills.insert(mp(mp(from, to), line));
					fills.insert(mp(mp(to, end), save));
					return ar;
				}
			}
			else
			{
				from = next;
				if (from == to) return st;
				i++;
			}
		}
		else i++;
	}
	return ar;
}

int main()
{
	calculatePrimes();

	int n;
	cin >> n;

	map<int, vector<int>> pos;

	for (int i = 0; i < n; i++)
	{
		int a;
		cin >> a;
		//a = rand() * 200000l / RAND_MAX;
		map<int,int> pr;
		for (int j = 0; j < primes.size() && a >= primes[j]*primes[j]; j++)
		{
			while (a%primes[j] == 0)
			{
				pr[primes[j]]++;
				a /= primes[j];
			}
		}
		if(a > 1)
			pr[a]++;
		fillMap(pr,pos,i,pr.begin(),-1);
	}

	map<int, vector<int>>::iterator i = pos.begin();

	set<pair<pair<int, int>, int>> fills;
	fills.insert(mp(mp(0, n), -1));

	long long totalsum = 0;

	while (i != pos.end())
	{
		vector<int> & cur = i->second;
		if (cur.size() <= 1) { i++; continue; }

		totalsum += insertSegment(0, cur[cur.size() - 2], fills) * i->first;
		totalsum += insertSegment(cur[0] + 1, cur.back(), fills) * i->first;
		totalsum += insertSegment(cur[1] + 1, n, fills) * i->first;

		i++;
	}
	cout << -totalsum;
}


//#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define Y imag()
#define X real()
#define inf 1000000000
#define eps 1e-9
#define Pi acos(-1)
using namespace std;
typedef complex<double> point;
int x[21],y[21],angle[21];
double memo[1<<20];
int n,sx,ex;
//constexpr double PI() {return acos(-1.0);}

double fun(double sx,int i)
{
   point p1(x[i],y[i]);
   point p2(sx,0);
   point v=p2-p1; ///vecteur directeur
   v*=exp(point(0,angle[i]*Pi/180)); /// nouveau vecteur directeur
                                     /// P(t) = p1+t*v equation de la droite aprés la rotation
                                     /// y(t) = y1+t*v
                                     /// 0 = p1.Y + t*v.Y intersection avec l'axe des abcisses
   if(atan2(v.Y,v.X)>-eps) {return ex;}
   double t = -p1.Y/v.Y;
   double x = p1.X+t*v.X;
   return x;
}

double solve(int mask)
{
   if(!mask) return sx;
   double &ret=memo[mask];
   if(ret == ret) return ret;
   ret=sx;
   for(int i=mask;i;i-=i&(-i))
   {
        int j=i&(-i);
        double x=solve(mask^j);
        ret = max(ret,fun(x,log2(j)+eps));

   }
   return memo[mask]=ret = min(ret,ex*1.0);
}

int main()
{   //ifstream cin("in");
    cin>>n>>sx>>ex;
    memset(memo,-1,sizeof memo);
    for(int i=0;i<n;i++) cin>>x[i]>>y[i]>>angle[i];
    double answ=solve((1<<(n))-1);
    cout<<fixed<<setprecision(9)<<answ-(double)sx;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <bitset>
#include <stack>
#include <iomanip>
#include <cmath>
#include <functional>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <ctime>
#include <chrono>
#include <climits>
#define mp make_pair
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
#define pb(x) push_back(x);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

#define MOD 998244353  //(1000*1000*1000+7)
#define inf1 2e9
#define inf2 2e18
default_random_engine generator;
uniform_int_distribution<int> distribution(1, INT_MAX);

vector<vector<long long> > one(int sz) {
	vector<vector<long long> > ret;
	ret.resize(sz);
	for (int i = 0; i<ret.size(); i++) {
		ret[i].resize(sz);
		for (int j = 0; j<ret.size(); j++) {
			ret[i][j] = (i == j);
		}
	}
	return ret;
}

vector<vector<long long> > mult(vector<vector<long long> > a, vector<vector<long long> > b) {
	vector<vector<long long > > ret;
	ret.resize(a.size());
	for (int i = 0; i<ret.size(); i++) {
		ret[i].resize(a.size());
		for (int j = 0; j<ret.size(); j++) {
			ret[i][j] = 0;
		}
	}
	for (int k = 0; k<ret.size(); k++) {
		for (int i = 0; i<a.size(); i++) {
			for (int j = 0; j<b.size(); j++) {
				ret[i][j] = (ret[i][j] + a[i][k] * b[k][j]);
				ret[i][j] %= MOD;
			}
		}
	}
	return ret;
}

vector<vector<long long> > pw(vector<vector<long long> > a, long long b) {
	if (b == 0)
		return one((int)a.size());
	if (b % 2)
		return mult(a, pw(a, b - 1));
	return pw(mult(a, a), b / 2);
}

ll my_rand(ll a = 0, ll b = INT_MAX) {
	return a + distribution(generator) % b;
}

inline int mul(int a, int b) {
	return int(a * 1ll * b % MOD);
}

inline int norm(int a) {
	if (a >= MOD)
		a -= MOD;
	if (a < 0)
		a += MOD;
	return a;
}

inline int binPow(int a, int k) {
	int ans = 1;
	while (k > 0) {
		if (k & 1)
			ans = mul(ans, a);
		a = mul(a, a);
		k >>= 1;
	}
	return ans;
}

inline int subtract(int a, int b) {
	return norm(a - b);
}

inline int sum(int a, int b) {
	return int((a + b) % MOD);
}

inline int inv(int a) {
	return binPow(a, MOD - 2);
}

ll ceil_int(ll a, ll b) {
	return a / b + (a%b != 0);
}

ll gcd(ll a, ll b) {
	if (a == 0)return b;
	return gcd(b%a, a);
}

ll lcm(ll a, ll b) {
	return (a*b) / gcd(a, b);
}

int main() {
	generator.seed(chrono::system_clock::now().time_since_epoch().count());
	cin.sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n;
	cin >> n;
	vector<pair<ll, ll>>p(n);
	string s;
	vector<int>used(n);
	int start_point = 0;
	vector<int>ans;
	for (int i = 0; i < n; i++) {
		int x, y;
		cin >> x >> y;
		p[i] = { x,y };
		if (p[start_point].second > p[i].second) {
			start_point = i;
		}
	}
	cin >> s;
	s += '#';
	ans.push_back(start_point);
	used[start_point] = 1;
	int current_point = start_point;
	for (int i = 0; i < n - 1; i++) {
		int next = -1;
		for (int j = 0; j < n; j++) {
			if (!used[j] && next == -1) {
				next = j;
			}
			else if (!used[j]) {
				ll x1 = p[next].first - p[current_point].first;
				ll y1 = p[next].second - p[current_point].second;
				ll x2 = p[j].first - p[current_point].first;
				ll y2 = p[j].second - p[current_point].second;
				if (s[i] == 'R') {
					if (x1*y2 - x2*y1 > 0) {
						next = j;
					}
				}
				else {
					if (x1*y2 - x2*y1 < 0) {
						next = j;
					}
				}
			}
		}
		used[next] = 1;
		current_point = next;
		ans.push_back(next);
	}
	for (int i = 0; i < n; i++) {
		cout << ans[i]+1 << " ";
	}
	return 0;
}


#include <bits/stdc++.h>
#define FOR(i, n) for(int i = 0; i < (n); ++i)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define TRAV(i, n) for(auto &i : (n))
#define SZ(x) (int)(x).size()
#define PR std::pair
#define MP std::make_pair
#define X first
#define Y second
typedef long long ll;
typedef std::pair<int, int> PII;
typedef std::vector<int> VI;

const int MOD = 1000000007;
int modpow(int a, int e){
	int ret = 1;
	while(e > 0){
		if(e&1) ret = (1ll*ret*a)%MOD;
		a = (1ll*a*a)%MOD;
		e>>=1;
	}
	return ret;
}

int pr[6][6];
int sub[2][1<<18];
int mas[1<<18];
int p[2][1<<20];
VI m3;
int comp[20];

int cm(int a){
	int ret = 0;
	FOR(i, 20) if(a & (1<<i)) ret += (1<<comp[i]);
	return ret;
}

int main(){
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(0);
	std::map<int, int> map;
	FOR(i, 1<<6) if(__builtin_popcount(i) == 3) m3.push_back(i), map[i] = SZ(m3)-1;
	FOR(i, 1<<6) if(__builtin_popcount(i) == 3) comp[map[i]] = map[i^63];
	assert(SZ(map) == 20);
	int n;
	std::cin >> n;
	FOR(i, n) FOR(j, n) std::cin >> pr[i][j], pr[i][j] = (1ll*pr[i][j]*modpow(100, MOD-2))%MOD;
	REP(i, n, 6) pr[i][i] = 1;
	n = 6;
	FOR(mask, 1<<18){
		sub[0][mask] = 1;
		sub[1][mask] = 1;
		FOR(i, 6) FOR(j, 3){
			if(mask & (1<<((i*3)+j))){
				sub[0][mask] = (1ll*sub[0][mask]*pr[i][j])%MOD;
				sub[1][mask] = (1ll*sub[1][mask]*pr[i][3+j])%MOD;
			}else{
				int od = 1-pr[i][j];
				if(od < 0) od += MOD;
				sub[0][mask] = (1ll*sub[0][mask]*od)%MOD;
				od = 1-pr[i][3+j];
				if(od < 0) od += MOD;
				sub[1][mask] = (1ll*sub[1][mask]*od)%MOD;
			}
		}
		int ind = 0;
		TRAV(m, m3){
			VI guys;
			FOR(i, 6) if(m & (1<<i)) guys.push_back(i);
			bool bad = false;
			FOR(xd, 1<<3){
				int ms = 0;
				FOR(i, 3) if(xd & (1<<i)) ms |= (mask >> (guys[i]*3)) & 7;
				if(__builtin_popcount(xd) > __builtin_popcount(ms)){
					bad = true;
					break;
				}
			}
			if(!bad) mas[mask] += (1<<ind);
			ind++;
		}
	}
	FOR(i, 1<<18) p[0][mas[i]] = (p[0][mas[i]]+sub[0][i])%MOD;
	FOR(i, 1<<18) p[1][cm(mas[i])] = (p[1][cm(mas[i])]+sub[1][i])%MOD;
	FOR(i, 20) FOR(mask, 1<<20) if(mask & (1<<i)) p[1][mask] = (p[1][mask]+p[1][mask^(1<<i)])%MOD;
	int ans = 0;
	FOR(i, 1<<20) ans = (1ll*ans+1ll*p[0][i]*p[1][i^((1<<20)-1)])%MOD;
	ans = 1-ans;
	if(ans < 0) ans += MOD;
	std::cout << ans << "\n";
	return 0;
}