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=0a - (a \oplus x) - x = 0 for some given aa, where ⊕\oplus 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 xx, 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=0a - (a \oplus x) - x = 0,其中 aa 是给定的整数,⊕\oplus 表示两个整数的按位异或(XOR)运算(该运算在许多现代编程语言中记为 ^ 或 xor)。奥伊拉-奥伊拉迅速找到了某个满足该方程的解 xx,但克里斯托瓦尔·洪塔认为奥伊拉-奥伊拉的结果还不够有趣,于是他问同事:这个方程有多少个非负整数解?这项任务对奥伊拉-奥伊拉而言过于困难,因此他请你来帮忙。

输入格式

Each test contains several possible values of aa and your task is to find the number of equation's solution for each of them. The first line contains an integer tt (1≤t≤10001 \le t \le 1000) — the number of these values.

The following tt lines contain the values of parameter aa, each value is an integer from 00 to 230−12^{30} - 1 inclusive.

每个测试包含若干个可能的 aa 值,你的任务是针对每个 aa 值求出该方程的解的个数。第一行包含一个整数 tt(1≤t≤10001 \le t \le 1000),表示此类 aa 值的个数。

接下来的 tt 行每行包含一个参数 aa 的值,每个值均为介于 00 到 230−12^{30} - 1(含端点)之间的整数。

输出格式

For each value of aa 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 aa appear in the input.

One can show that the number of solutions is always finite.

对于每个 aa 的值,恰好输出一个整数——即给定参数值下该方程的非负解的个数。请按照输入中 aa 值出现的顺序输出答案。

可以证明,解的个数总是有限的。

输入输出样例

  • 输入#1

    3
    0
    2
    1073741823

    输出#1

    1
    2
    1073741824

说明/提示

Let's define the bitwise exclusive OR (XOR) operation. Given two integers xx and yy, consider their binary representations (possibly with leading zeroes): xk…x2x1x0x_k \dots x_2 x_1 x_0 and yk…y2y1y0y_k \dots y_2 y_1 y_0. Here, xix_i is the ii-th bit of the number xx and yiy_i is the ii-th bit of the number yy. Let r=x⊕yr = x \oplus y be the result of the XOR operation of xx and yy. Then rr is defined as rk…r2r1r0r_k \dots r_2 r_1 r_0 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=0x = 0 is a solution of the equation.

For the second value of the parameter, solutions are x=0x = 0 and x=2x = 2.

我们来定义按位异或(XOR)运算。给定两个整数 xx 和 yy,考虑它们的二进制表示(允许有前导零):xk…x2x1x0x_k \dots x_2 x_1 x_0 和 yk…y2y1y0y_k \dots y_2 y_1 y_0。其中,xix_i 表示数 xx 的第 ii 位,yiy_i 表示数 yy 的第 ii 位。令 r=x⊕yr = x \oplus y 为 xx 与 yy 的异或运算结果,则 rr 定义为 rk…r2r1r0r_k \dots r_2 r_1 r_0,其中:

r\_i = \\left\\{ \\begin{aligned} 1, ~ \\text{若} ~ x\_i \\ne y\_i \\\\ 0, ~ \\text{若} ~ x\_i = y\_i \\end{aligned} \\right.

对于参数的第一个取值,方程的唯一解是 x=0x = 0。

对于参数的第二个取值,方程的解为 x=0x = 0 和 x=2x = 2。

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

首页