AtCoder Regular Contest-- 224
D
所有点对的焦虑
Angst for All Pairs
AtCoder
⌀ 1573
原题
← CE →

所有点对的焦虑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$ 中的一个。
AI (CI翻译)

$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$。
  • 所有输入值均为整数。
AI (CI翻译)

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}_T
AI (CI翻译)

Each test case is given in the following format:

每个测试用例按照以下格式给出:AI (CI翻译)

N K

N K
AI (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翻译)

样例

Input #1
4
3 5
100 25
5 1225
180 998244
Output #1
5
39
-1
17655598
This input contains four test cases. For the first test case, writing as follows satisfies the condition with a total cost of $5$. - Write $1, 5$ on card $1$. - Write $2, 5$ on card $2$. - Write $3$ on card $3$. For the second test case, the minimum total cost required to satisfy the condition is $39$. For the third test case, it is impossible to satisfy the condition, so output $-1$. For the fourth test case, the minimum total cost required to satisfy the condition is $17655598$.
题目信息
题号
arc224_d
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。