文理学院程序设计在线练习


boring sum

Time Limit: 2 Second(s)    Memory Limit: 32 MB

Total Submission(s): 26   Accepted Submission(s): 9
Problem Description

Number theory is interesting, while this problem is boring.
Here is the problem. Given an integer sequence a[1], a[2], …, a[n], let S(i) = {a[j]|1<=j<i, and a[j] is a multiple of a[i]}. If S(i) is not empty, let f(i) be the maximum integer in S(i); otherwise, f(i) = a[i]. Now we define b[¬i] as f(i). Similarly, let T(i) = {a[j]|i<j<=n, and a[j] is a multiple of a[i]}. If T(i) is not empty, let g(i) be the minimum integer in T(i); otherwise, g(i) = a[i]. Now we define c[i] as g(i). The boring sum of this sequence is defined as b[1] * c[1] + b[2] * c[2] + … + b[n] * c[n].
Given an integer sequence, your task is to calculate its boring sum.

Input

The input contains multiple test cases.
Each case consists of two lines. The first line contains an integer n (1<=n<=100000). The second line contains n integers a1, a2, …, an (1<= ai<=100000).
The input is terminated by n = 0.

Output

Output the answer in a line.

Sample Input
5
1 4 2 3 9
0
Sample Output
134
Source

2014市赛