CF2203C.Test Generator
普及/提高-
通过率:0%
时间限制:2.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are developing a test generator. It takes two integers s and m as input. You need to construct an array of non-negative integers a=[a1,a2,…,an] such that:
- i=1∑nai=s;
- for each i, the condition ai&m=ai holds, where & denotes the bitwise AND operator.
In other words, in each number ai, the bits that are set to one can only be in the positions where the bits in the number m are also set to one.
Determine whether there exists at least one such array. If it exists, find the minimum possible length n.
你正在开发一个测试用例生成器。它接收两个整数 s 和 m 作为输入。你需要构造一个由非负整数组成的数组 a=[a1,a2,…,an],满足以下条件:
- i=1∑nai=s;
- 对每个 i,均满足 ai&m=ai,其中 & 表示按位与运算符。
换言之,对每个数 ai,其二进制表示中值为 1 的比特位,只能出现在 m 的二进制表示中同样为 1 的比特位上。
请判断是否存在至少一个满足上述条件的数组。若存在,求出最小可能的数组长度 n。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤104). The description of the test cases follows.
Each test case consists of a single line containing two integers s and m (1≤s,m≤1018) — parameters of the generator.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤104)。随后是各测试用例的描述。
每个测试用例由一行组成,包含两个整数 s 和 m(1≤s,m≤1018)——生成器的参数。
输出格式
For each test case, print one integer:
- if such an array does not exist, print −1;
- otherwise, print the minimum possible value of n — the length of the array.
对于每个测试用例,输出一个整数:
- 如果这样的数组不存在,则输出 −1;
- 否则,输出 n 的最小可能值——即数组的长度。
输入输出样例
输入#1
6 13 5 13 3 13 6 1000000007 2776648 99999999999 1 998244353 1557287
输出#1
3 5 -1 -1 99999999999 642
说明/提示
Let's analyze some examples:
- For s=13,m=5, the answer is 3, as there is a suitable array a=[5,4,4];
- For s=13,m=3, the answer is 5, as there is a suitable array a=[3,3,3,3,1];
- For s=13,m=6, the answer is −1, as there is no suitable array.
我们来分析一些例子:
- 当 s=13,m=5 时,答案为 3,因为存在一个满足条件的数组 a=[5,4,4];
- 当 s=13,m=3 时,答案为 5,因为存在一个满足条件的数组 a=[3,3,3,3,1];
- 当 s=13,m=6 时,答案为 −1,因为不存在满足条件的数组。
输入解题思路,AI测评打分。不知道怎么写?