import java.io.*; import java.util.*; class Main { public static void main(String args[])throws Exception { BufferedReader bu=new BufferedReader(new InputStreamReader(System.in)); StringBuilder sb=new StringBuilder(); int n=Integer.parseInt(bu.readLine()); String s[]=bu.readLine().split(" "); /* a[i]%a[j]-a[j]%a[i]; consider a[i]0;i--) { long here=query(c,i)-query(c,i-1); //how many i's are there in array int j=1; long aij=0,aji; while(j*i<=N) { long count=query(c,Math.min(j*i+i-1,N))-query(c,j*i-1); long tot=query(sum,Math.min(j*i+i-1,N))-query(sum,j*i-1); aij+=tot-count*i*j; j++; } aji=(query(c,N)-query(c,i))*i; ans+=Math.abs(aij-aji)*here; } System.out.println(ans); } static void update(long bit[],int i,int v,int n) { while(i<=n) { bit[i]+=v; i+=i&-i; } } static long query(long bit[],int i) { long s=0; while(i>0) { s+=bit[i]; i-=i&-i; } return s; } }