luogu#P1390. 公约数的和

    ID: 385 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>数学O2优化莫比乌斯反演整除分块

公约数的和

Background

One day, TIBBAR and LXL competed to see who could first compute the sum of the greatest common divisors of every pair of distinct numbers among the nn numbers from 1n1 \sim n. LXL is still typing a complicated and lengthy program, hoping to get an answer within 100s100s. TIBBAR, however, wants to pass in 1s1s for a decisive win; please help him accomplish this task.

Problem 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