#include<iostream>
#include<cstdio>
#include<vector>
#include<cstring>
#define maxn 100010
#define maxm 100010
using namespace std;
int n;
int a[maxn],b[maxn],c[maxn],mark[maxm];
vector<int> adj[maxm];
int main()
{
for (int i=1;i<maxm;i++) adj[i].clear(); //二维的要一维一维地清空;
for (int i=1;i<maxm;i++)
for (int j=1;j<maxm/i;j++)
adj[i*j].push_back(i); //通过循环将i*j的约数储存起来;
while (1){
scanf("%d",&n);
if (!n) break;
for (int i=1;i<=n;i++) scanf("%d",&a[i]);
memset(mark,0,sizeof(mark));
for (int i=1;i<=n;i++) //从左往右扫描,找b[i]
{
if (mark[a[i]]==0) b[i]=a[i]; //未被更新,a[i]的最大值更新为本身
else b[i]=mark[a[i]];
for (int j=0;j<adj[a[i]].size();j++)
{
int d=adj[a[i]][j]; //a[i]的第j个约数为d;
mark[d]=a[i]; //那么mark[d]的值更新为a[i];即:将a[i]的约数的mark值都标记为a[i],当a[i]之后扫到其约数,因为这一步更新了,就直接读取mark值,即a[i];
}
}
memset(mark,0,sizeof(mark)); //再将mark数组清空
for (int i=n;i>=1;i--) //然后从右往左扫描,找c[i]
{
if (mark[a[i]]==0) c[i]=a[i];else c[i]=mark[a[i]];
for (int j=0;j<adj[a[i]].size();j++)
{
int d=adj[a[i]][j];
mark[d]=a[i];
}
}
long long ans=0;
for (int i=1;i<=n;i++)
ans+=(long long)b[i]*(long long)c[i];
printf("%I64d\n",ans);
}
return 0;
}