CF1064B.Equations of Mathematical Magic
普及-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Colossal! — exclaimed Hawk-nose. — A programmer! That's exactly what we are looking for.
Arkadi and Boris Strugatsky. Monday starts on Saturday
Reading the book "Equations of Mathematical Magic" Roman Oira-Oira and Cristobal Junta found an interesting equation: a−(a⊕x)−x=0 for some given a, where ⊕ stands for a bitwise exclusive or (XOR) of two integers (this operation is denoted as ^ or xor in many modern programming languages). Oira-Oira quickly found some x, which is the solution of the equation, but Cristobal Junta decided that Oira-Oira's result is not interesting enough, so he asked his colleague how many non-negative solutions of this equation exist. This task turned out to be too difficult for Oira-Oira, so he asks you to help.
太棒了!——鹰钩鼻惊呼道。——一名程序员!这正是我们一直在寻找的人。
阿尔卡季·斯特鲁加茨基与鲍里斯·斯特鲁加茨基,《星期六开始的星期一》
罗曼·奥伊拉-奥伊拉和克里斯托瓦尔·洪塔在阅读《数学魔法方程》一书时,发现了一个有趣的方程:a−(a⊕x)−x=0,其中 a 是给定的整数,⊕ 表示两个整数的按位异或(XOR)运算(该运算在许多现代编程语言中记为 ^ 或 xor)。奥伊拉-奥伊拉迅速找到了某个满足该方程的解 x,但克里斯托瓦尔·洪塔认为奥伊拉-奥伊拉的结果还不够有趣,于是他问同事:这个方程有多少个非负整数解?这项任务对奥伊拉-奥伊拉而言过于困难,因此他请你来帮忙。
输入格式
Each test contains several possible values of a and your task is to find the number of equation's solution for each of them. The first line contains an integer t (1≤t≤1000) — the number of these values.
The following t lines contain the values of parameter a, each value is an integer from 0 to 230−1 inclusive.
每个测试包含若干个可能的 a 值,你的任务是针对每个 a 值求出该方程的解的个数。第一行包含一个整数 t(1≤t≤1000),表示此类 a 值的个数。
接下来的 t 行每行包含一个参数 a 的值,每个值均为介于 0 到 230−1(含端点)之间的整数。
输出格式
For each value of a print exactly one integer — the number of non-negative solutions of the equation for the given value of the parameter. Print answers in the same order as values of a appear in the input.
One can show that the number of solutions is always finite.
对于每个 a 的值,恰好输出一个整数——即给定参数值下该方程的非负解的个数。请按照输入中 a 值出现的顺序输出答案。
可以证明,解的个数总是有限的。
输入输出样例
输入#1
3 0 2 1073741823
输出#1
1 2 1073741824
说明/提示
Let's define the bitwise exclusive OR (XOR) operation. Given two integers x and y, consider their binary representations (possibly with leading zeroes): xk…x2x1x0 and yk…y2y1y0. Here, xi is the i-th bit of the number x and yi is the i-th bit of the number y. Let r=x⊕y be the result of the XOR operation of x and y. Then r is defined as rk…r2r1r0 where:
r\_i = \\left\\{ \\begin{aligned} 1, ~ \\text{if} ~ x\_i \\ne y\_i \\\\ 0, ~ \\text{if} ~ x\_i = y\_i \\end{aligned} \\right.For the first value of the parameter, only x=0 is a solution of the equation.
For the second value of the parameter, solutions are x=0 and x=2.
我们来定义按位异或(XOR)运算。给定两个整数 x 和 y,考虑它们的二进制表示(允许有前导零):xk…x2x1x0 和 yk…y2y1y0。其中,xi 表示数 x 的第 i 位,yi 表示数 y 的第 i 位。令 r=x⊕y 为 x 与 y 的异或运算结果,则 r 定义为 rk…r2r1r0,其中:
r\_i = \\left\\{ \\begin{aligned} 1, ~ \\text{若} ~ x\_i \\ne y\_i \\\\ 0, ~ \\text{若} ~ x\_i = y\_i \\end{aligned} \\right.对于参数的第一个取值,方程的唯一解是 x=0。
对于参数的第二个取值,方程的解为 x=0 和 x=2。
输入解题思路,AI测评打分。不知道怎么写?