#P1390. 公约数的和

    ID: 385 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>数学O2优化素数判断,质数,筛法最大公约数,gcd莫比乌斯反演

公约数的和

Description

Given nn, compute

i=1nj=i+1ngcd(i,j)\sum_{i = 1}^n \sum_{j = i + 1}^n \gcd(i, j)

where gcd(i,j)\gcd(i, j) denotes the greatest common divisor of ii and jj.

Input Format

The input consists of a single line with one integer, denoting nn.

Output Format

Output a single line with one integer representing the answer.

10

67

Hint

Constraints

  • For 40% of the testdata, n2×103n \leq 2 \times 10^3.
  • For 100% of the testdata, 2n2×1062 \leq n \leq 2 \times 10^6.

Translated by ChatGPT 5