## https://yukicoder.me/problems/no/1233 import math def main(): N = int(input()) A = list(map(int, input().split())) A.sort() cum_a_list = [0] * (N + 1) for i in range(N): cum_a_list[i + 1] = cum_a_list[i] + A[i] a_map = {} for a in A: if a not in a_map: a_map[a] = 0 a_map[a] += 1 a_keys = list(a_map.keys()) a_keys.sort() sqrt_a = int(math.sqrt(a_keys[-1])) # Aの値がmod未満のものをcount index = 0 a0 = a_keys[index] answer = 0 while a0 <= sqrt_a + 1: for a in A: m = a % a0 answer += m * a_map[a0] if index < len(a_keys) - 1: index += 1 a0 = a_keys[index] else: break # Aの商がsqrt_a以下のものをcount while index < len(a_keys): max_k = a_keys[-1] // a0 v = -1 q = 0 while q <= max_k: low = v + 1 high = len(A) - 1 if A[low] >= (q + 1) * a0: q += 1 continue low = v + 1 high = len(A) - 1 if high - low < 0: break while high - low > 1: mid = (low + high) // 2 if A[mid] < (q + 1) * a0: low = mid else: high = mid if A[high] < (q + 1) * a0: v0 = high else: v0 = low c = v0 - v a_sum = cum_a_list[v0 + 1] - cum_a_list[v + 1] ans = a_sum - c * q * a0 answer += ans * a_map[a0] v = v0 if v == len(A) - 1: break else: q = A[v + 1] // a0 if index < len(a_keys) - 1: index += 1 a0 = a_keys[index] else: break print(answer) if __name__ == "__main__": main()