#include <iostream> #include <cstdlib> #include <cstring> #include <string> #include <cstdio> #include <cmath> #include <algorithm> #include <vector> #include <queue> #include <map> #define inf 0x3f3f3f3f #pragma comment(linker, "/STACK:16777216") #define eps 1e-6 #define ll long long using namespace std; const int maxn=100010; vector<int> v[maxn]; int a[maxn],b[maxn],s[maxn],h[maxn]; int main() { int i,j,n; for(i=1;i<maxn;i++)//预处理每个数的约数 注意这里不能取等 不然超了 for(j=i;j<maxn;j+=i) v[j].push_back(i); while(~scanf("%d",&n)&&n) { for(i=1;i<=n;i++) scanf("%d",s+i); memset(h,-1,sizeof h); for(i=1;i<=n;i++) { if(h[s[i]]!=-1) b[i]=s[h[s[i]]]; else b[i]=s[i]; for(j=0;j<v[s[i]].size();j++) h[v[s[i]][j]]=i; } memset(h,-1,sizeof h); for(i=n;i>0;i--) { if(h[s[i]]!=-1) a[i]=s[h[s[i]]]; else a[i]=s[i]; for(j=0;j<v[s[i]].size();j++) h[v[s[i]][j]]=i; } ll ans=0; for(i=1;i<=n;i++) ans+=(ll)a[i]*b[i]; cout<<ans<<endl; } return 0; }
hdu4961 Boring Sum,布布扣,bubuko.com
时间: 2024-10-20 23:07:53