CF1646A.Square Counting

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Luis has a sequence of n+1n+1 integers a1,a2,…,an+1a_1, a_2, \ldots, a_{n+1}. For each i=1,2,…,n+1i = 1, 2, \ldots, n+1 it is guaranteed that 0≤ai<n0\leq a_i \lt n, or ai=n2a_i=n^2. He has calculated the sum of all the elements of the sequence, and called this value ss.

Luis has lost his sequence, but he remembers the values of nn and ss. Can you find the number of elements in the sequence that are equal to n2n^2?

We can show that the answer is unique under the given constraints.

路易斯有一个由 n+1n+1 个整数组成的序列 a1,a2,…,an+1a_1, a_2, \ldots, a_{n+1}。对每个 i=1,2,…,n+1i = 1, 2, \ldots, n+1,保证满足 0≤ai<n0\leq a_i \lt n 或 ai=n2a_i=n^2。他计算了该序列所有元素的和,并将该值记为 ss。

路易斯丢失了他的序列,但他还记得 nn 和 ss 的值。你能找出该序列中等于 n2n^2 的元素个数吗?

在给定约束条件下,答案是唯一的。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤2⋅1041 \le t \le 2\cdot 10^4). Description of the test cases follows.

The only line of each test case contains two integers nn and ss (1≤n<1061\le n \lt 10^6, 0≤s≤10180\le s \le 10^{18}). It is guaranteed that the value of ss is a valid sum for some sequence satisfying the above constraints.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤2⋅1041 \le t \le 2\cdot 10^4)。随后是测试用例的描述。

每个测试用例仅有一行,包含两个整数 nn 和 ss(1≤n<1061\le n \lt 10^6,0≤s≤10180\le s \le 10^{18})。保证 ss 的值对于满足上述约束的某个序列是有效的和。

输出格式

For each test case, print one integer — the number of elements in the sequence which are equal to n2n^2.

对于每个测试用例,输出一个整数——序列中等于 n2n^2 的元素个数。

输入输出样例

  • 输入#1

    4
    7 0
    1 1
    2 12
    3 12

    输出#1

    0
    1
    3
    1

说明/提示

In the first test case, we have s=0s=0 so all numbers are equal to 00 and there isn't any number equal to 4949.

In the second test case, we have s=1s=1. There are two possible sequences: [0,1][0, 1] or [1,0][1, 0]. In both cases, the number 11 appears just once.

In the third test case, we have s=12s=12, which is the maximum possible value of ss for this case. Thus, the number 44 appears 33 times in the sequence.

在第一个测试用例中,我们有 s=0s=0,因此所有数字都等于 00,且序列中不存在等于 4949 的数字。

在第二个测试用例中,我们有 s=1s=1。存在两种可能的序列:[0,1][0, 1] 或 [1,0][1, 0]。在这两种情况下,数字 11 均恰好出现一次。

在第三个测试用例中,我们有 s=12s=12,这是本测试用例中 ss 的最大可能值。因此,数字 44 在序列中出现了 33 次。

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

首页