所有点对的焦虑AI (CI翻译)
Problem Statement
题目描述
AI (CI翻译)There are $N$ cards, numbered $1$ through $N$. Initially, nothing is written on any of the cards.
有 $N$ 张卡片,编号为 $1$ 至 $N$。初始时,所有卡片上都没有写任何内容。AI (CI翻译)
You can write zero or more positive integers on each card.
你可以在每张卡片上写入零个或多个正整数。AI (CI翻译)
The cost of writing a positive integer $k$ once is equal to the number of digits in the decimal representation of $k$.
在一张卡片上写入一次正整数 $k$ 的代价,等于 $k$ 的十进制表示的位数。AI (CI翻译)
Determine whether it is possible to satisfy the following condition. If it is possible, output the minimum total cost required; if it is not possible, output $-1$.
请判断是否可以满足以下条件。若可以,输出所需的最小总代价;若不可以,输出 $-1$。AI (CI翻译)
- For every pair of positive integers
$(x,y)$satisfying$1 \leq x < y \leq K$, there exists a card containing exactly one of$x$and$y$.
- 对于满足
$1 \leq x < y \leq K$的每一对正整数$(x,y)$,都存在一张卡片,使得该卡片上恰好包含$x$和$y$中的一个。
$T$ test cases are given; solve each of them.
给出 $T$ 个测试用例,请分别求出每个测试用例的答案。AI (CI翻译)
Constraints
约束条件
AI (CI翻译)$1 \leq T \leq 10^5$$1 \leq N \leq 10^6$$2 \leq K \leq 10^6$- The sum of
$N$in each input is at most$10^6$. - The sum of
$K$in each input is at most$10^6$. - All input values are integers.
$1 \leq T \leq 10^5$$1 \leq N \leq 10^6$$2 \leq K \leq 10^6$- 每个输入中所有
$N$的总和不超过$10^6$。 - 每个输入中所有
$K$的总和不超过$10^6$。 - 所有输入值均为整数。
Input
输入格式
AI (CI翻译)The input is given from Standard Input in the following format, where $\mathrm{case}_i$ denotes the $i$-th test case:
输入从标准输入按照以下格式给出,其中 $\mathrm{case}_i$ 表示第 $i$ 个测试用例:AI (CI翻译)
T
\mathrm{case}_1
\mathrm{case}_2
\vdots
\mathrm{case}_T
T
\mathrm{case}_1
\mathrm{case}_2
\vdots
\mathrm{case}_TAI (CI翻译)
Each test case is given in the following format:
每个测试用例按照以下格式给出:AI (CI翻译)
N K
N KAI (CI翻译)
Output
输出格式
AI (CI翻译)Output $T$ lines. The $i$-th line should contain the answer for the $i$-th test case.
输出 $T$ 行。第 $i$ 行应包含第 $i$ 个测试用例的答案。AI (CI翻译)
样例
4
3 5
100 25
5 1225
180 998244
5
39
-1
17655598
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。