Problems > Sum of Pairwise GCDs

Sum of Pairwise GCDs

Difficulty: 2100 6000 ms 128 MB

number-theory

Print ∑i<j gcd(ai, aj).

Input: the first line has N; the second line has N positive integers.

Output: the sum of gcd over all pairs.

Constraints:

  • 2 ≤ N ≤ 105
  • 1 ≤ ai ≤ 105

Sample Tests

Input 1
3
2 4 6
Output 1
6
Input 2
2
5 5
Output 2
5

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.