url:https://ac.nowcoder.com/acm/contest/625/H
1.1
2.2 1.2
3.3 2.3 1.3
4.4 3.4 2.3 1.3
.......
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define maxn 500005
const int mod = 1000000007;
typedef pair<int,int>P;
vector<P>vv[maxn];
ll n,nn,a[maxn];
ll l,r;
ll res;
ll gcd(ll a,ll b)
{
return b?gcd(b,a%b):a;
}
void update(ll v)
{
ll last=r;
ll tmp=0;
for(ll i=0;i<vv[r].size();i++)
{
ll g=vv[r][i].first,p=vv[r][i].second;
tmp+=1ll*(last-p+1)*g,last=p-1;
// cout<<tmp<<endl;
}
// cout<<endl;
res = (res%mod + 1ll*v*tmp%mod)%mod;
}
int main()
{
scanf("%lld",&n);
nn=(int)(sqrt(1.0*n)+0.5);
for(ll i=1;i<=n;i++)
{
scanf("%lld",&a[i]);
vv[i].clear();
}
vv[0].clear();
for(ll i=1;i<=n;i++)
{
ll x=a[i],y=i;
for(ll j=0;j<vv[i-1].size();j++)
{
ll g=gcd(vv[i-1][j].first,a[i]);
if(g!=x)
{
vv[i].push_back(P(x,y));
// cout<<x<<" "<<y<<endl;
x=g;
}
y=vv[i-1][j].second;
}
vv[i].push_back(P(x,y));
// cout<<x<<" "<<y<<endl;
// cout<<endl;
}
res=0;
while(r<=n)
{
r++,update(1);
}
printf("%lld\n",res);
return 0;
}