A14938 | Square Counting
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Luis has a sequence of $n+1$ integers $a_1, a_2, \ldots, a_{n+1}$ . For each $i = 1, 2, \ldots, n+1$ it is guaranteed that $0\leq a_i < n$ , or $a_i=n^2$ . He has calculated the sum of all the elements of the sequence, and called this value $s$ .
Luis has lost his sequence, but he remembers the values of $n$ and $s$ . Can you find the number of elements in the sequence that are equal to $n^2$ ?
We can show that the answer is unique under the given constraints.
Luis has lost his sequence, but he remembers the values of $n$ and $s$ . Can you find the number of elements in the sequence that are equal to $n^2$ ?
We can show that the answer is unique under the given constraints.
输入格式
Each test contains multiple test cases. The first line contains the number of test cases $t$ ( $1 \le t \le 2\cdot 10^4$ ). Description of the test cases follows.
The only line of each test case contains two integers $n$ and $s$ ( $1\le n< 10^6$ , $0\le s \le 10^{18}$ ). It is guaranteed that the value of $s$ is a valid sum for some sequence satisfying the above constraints.
The only line of each test case contains two integers $n$ and $s$ ( $1\le n< 10^6$ , $0\le s \le 10^{18}$ ). It is guaranteed that the value of $s$ is a valid sum for some sequence satisfying the above constraints.
输出格式
For each test case, print one integer — the number of elements in the sequence which are equal to $n^2$ .
输入输出样例
输入 #1
4 7 0 1 1 2 12 3 12
输出 #1
0 1 3 1
In the first test case, we have $s=0$ so all numbers are equal to $0$ and there isn't any number equal to $49$ .
In the second test case, we have $s=1$ . There are two possible sequences: $[0, 1]$ or $[1, 0]$ . In both cases, the number $1$ appears just once.
In the third test case, we have $s=12$ , which is the maximum possible value of $s$ for this case. Thus, the number $4$ appears $3$ times in the sequence.
In the second test case, we have $s=1$ . There are two possible sequences: $[0, 1]$ or $[1, 0]$ . In both cases, the number $1$ appears just once.
In the third test case, we have $s=12$ , which is the maximum possible value of $s$ for this case. Thus, the number $4$ appears $3$ times in the sequence.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted