CF1603D.Artistic Partition

NOI/NOI+/CTSC

通过率:0%

时间限制:3.00s

内存限制:1024MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

For two positive integers ll and rr (l≤rl \le r) let c(l,r)c(l, r) denote the number of integer pairs (i,j)(i, j) such that l≤i≤j≤rl \le i \le j \le r and gcd⁡(i,j)≥l\operatorname{gcd}(i, j) \ge l. Here, gcd⁡(i,j)\operatorname{gcd}(i, j) is the greatest common divisor (GCD) of integers ii and jj.

YouKn0wWho has two integers nn and kk where 1≤k≤n1 \le k \le n. Let f(n,k)f(n, k) denote the minimum of ∑i=1kc(xi+1,xi+1)\sum\limits_{i=1}^{k}{c(x_i+1,x_{i+1})} over all integer sequences 0=x1<x2<…<xk<xk+1=n0=x_1 \lt x_2 \lt \ldots \lt x_{k} \lt x_{k+1}=n.

Help YouKn0wWho find f(n,k)f(n, k).

对于两个正整数 ll 和 rr(满足 l≤rl \le r),定义 c(l,r)c(l, r) 为满足 l≤i≤j≤rl \le i \le j \le r 且 gcd⁡(i,j)≥l\operatorname{gcd}(i, j) \ge l 的整数对 (i,j)(i, j) 的个数。其中,gcd⁡(i,j)\operatorname{gcd}(i, j) 表示整数 ii 与 jj 的最大公约数(GCD)。

YouKn0wWho 有两个整数 nn 和 kk,满足 1≤k≤n1 \le k \le n。定义 f(n,k)f(n, k) 为对所有满足 0=x1<x2<…<xk<xk+1=n0 = x_1 < x_2 < \ldots < x_k < x_{k+1} = n 的整数序列,表达式 ∑i=1kc(xi+1,xi+1)\sum\limits_{i=1}^{k}{c(x_i+1,x_{i+1})} 的最小值。

请帮助 YouKn0wWho 求出 f(n,k)f(n, k)。

输入格式

The first line contains a single integer tt (1≤t≤3⋅1051 \le t \le 3 \cdot 10^5) — the number of test cases.

The first and only line of each test case contains two integers nn and kk (1≤k≤n≤1051 \le k \le n \le 10^5).

第一行包含一个整数 tt(1≤t≤3⋅1051 \le t \le 3 \cdot 10^5)—— 测试用例的数量。

每个测试用例仅有一行,包含两个整数 nn 和 kk(1≤k≤n≤1051 \le k \le n \le 10^5)。

输出格式

For each test case, print a single integer — f(n,k)f(n, k).

对于每个测试用例,输出一个整数——f(n,k)f(n, k)。

输入输出样例

  • 输入#1

    4
    6 2
    4 4
    3 1
    10 3

    输出#1

    8
    4
    6
    11

说明/提示

In the first test case, YouKn0wWho can select the sequence [0,2,6][0, 2, 6]. So f(6,2)=c(1,2)+c(3,6)=3+5=8f(6, 2) = c(1, 2) + c(3, 6) = 3 + 5 = 8 which is the minimum possible.

在第一个测试用例中,YouKn0wWho 可以选择序列 [0,2,6][0, 2, 6]。因此 f(6,2)=c(1,2)+c(3,6)=3+5=8f(6, 2) = c(1, 2) + c(3, 6) = 3 + 5 = 8,这是可能的最小值。

输入解题思路,AI测评打分。不知道怎么写?

首页