/*
ID: neverchanje
PROG:
LANG: C++11
*/
#include<vector>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<set>
#include<queue>
#include<map>
using namespace std;
#define INF 1e9
#define maxn 100010
#define rep(i,x,y) for(int i=x;i<=y;i++)
#define mset(x) memset(x,0,sizeof(x))
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
int a[maxn], n, b[maxn], c[maxn], h[maxn];
int main(){
// freopen("a.txt","r",stdin);
// freopen(".out","w",stdout);
while(cin>>n && n){
rep(i,1,n)
cin>>a[i];
mset(b);mset(c);
mset(h);
rep(i,1,n){
if(!h[a[i]]) b[i] = a[i];
else b[i]=h[a[i]];
for(int j=1;j<=sqrt(a[i]+0.5);j++){
if(a[i]%j==0){
h[j] = a[i];
h[a[i]/j] = a[i];
}
}
}
mset(h);
for(int i=n;i>=1;i--){
if(!h[a[i]]) c[i]=a[i];
else c[i] = h[a[i]];
for(int j=1;j<=sqrt(a[i]+0.5);j++){
if(a[i]%j==0){
h[j] = a[i];
h[a[i]/j] = a[i];
}
}
}
ll sum=0;
rep(i,1,n){
sum+=((ll)b[i])*c[i];
}
cout<<sum<<endl;
}
return 0;
}
/*
DESCRIPTION:
*/
hdu4961 求离i最近的a[i]的倍数 因子拆分+递推
最新推荐文章于 2023-03-13 18:40:04 发布