Description

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.

Input

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.

Output

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.

Sample Input

Input
3
0
2
1073741823
Output
1
2
1073741824 题目意思:已知a,求解方程a−(a⊕x)−x=0,x的可能情况有几种。
解题思路:通过移项我们可以得到a⊕x=a-x,那么我们需要找一下这两个表达式的联系和区别。因为是异或,我们将这两个数放在二进制下比较。

1^1=0 1-1=0
   1^0=1 1-0=1
   0^0=0 0-0=0
   0^1=1 0-1=1//借位

我们可以发现,当a=1时,不管对于位上的x是0还是1,都是成立的,但当a=0时,只有x=0成立。
因而发现a=1时可以有两种选择,那么只需要统计a的二进制中1的个数,根据乘法原则就能求出所有解的个数了。
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
/*
1^1=0 1-1=0
1^0=1 1-0=1
0^0=0 0-0=0
0^1=1 0-1=1//借位
*/
int main()
{
int a,b,t,ans;
scanf("%d",&t);
while(t--)
{
scanf("%d",&a);
ans=;
while(a)
{
if(a%)
{
ans=ans*;
}
a/=;
}
printf("%d\n",ans);
}
return ;
}


CF 1064B Equations of Mathematical Magic(思维规律)的更多相关文章

  1. cf#516B. Equations of Mathematical Magic(二进制,位运算)

    https://blog.csdn.net/zfq17796515982/article/details/83051495 题意:解方程:a-(a^x)-x=0 给出a的值,要求计算解(非负)的个数 ...

  2. B. Equations of Mathematical Magic

    思路 打表找规律,发现结果是,2的(a二进制位为1总数)次方 代码 #include<bits/stdc++.h> using namespace std; #define ll long ...

  3. CF1064B 【Equations of Mathematical Magic】

    题目要求解$a-(a\oplus x)-x=0$的解$x$的个数 移项得$a-x=a\oplus x$ $a$的二进制形式,应该是一个$01$串,异或的过程是不能影响到两个不同的位的,所以我们按位考虑 ...

  4. [ CodeForces 1064 B ] Equations of Mathematical Magic

    \(\\\) \(Description\) \(T\) 组询问,每次给出一个 \(a\),求方程 \[ a-(a\oplus x)-x=0 \] 的方案数. \(T\le 10^3,a\le 2^{ ...

  5. UVa10025 The ? 1 ? 2 ? ... ? n = k problem 数学思维+规律

    UVa10025 ? 1 ? 2 ? ... ? n = k problem The problem Given the following formula, one can set operator ...

  6. Codeforces CF#628 Education 8 D. Magic Numbers

    D. Magic Numbers time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  7. cf A. Inna and Pink Pony(思维题)

    题目:http://codeforces.com/contest/374/problem/A 题意:求到达边界的最小步数.. 刚开始以为是 bfs,不过数据10^6太大了,肯定不是... 一个思维题, ...

  8. [ 9.29 ]CF每日一题系列—— 765B字符串规律

    Description: 遇到了ogo可以变成***如果ogo后面有go统统忽略,输出结果 Solution: 哎如果我一开始对题意的解读如上的话,就不会被整的那么麻烦了 Code: #include ...

  9. CF 1042 E. Vasya and Magic Matrix

    E. Vasya and Magic Matrix http://codeforces.com/contest/1042/problem/E 题意: 一个n*m的矩阵,每个位置有一个元素,给定一个起点 ...

随机推荐

  1. Spring AOP源码分析(一)使用示例

    摘要: 本文结合<Spring源码深度解析>来分析Spring 5.0.6版本的源代码.若有描述错误之处,欢迎指正. 我们知道,使用面向对象编程(OOP)有一些弊端,当需要为多个不具有继承 ...

  2. C语言程序设计I—第三周教学

    由于本课程是从教学周的第二周开始上课,所以第二次授课是发生在第三周,为了让PTA.云班课和博客能统一,所以将教学周作为随笔的标题.本周由于处理外聘教师随意退课等事情,总结有些延后了. 第三周教学安排 ...

  3. 从CMDB查询云平台组件或者IP简单脚本

    #!/bin/bash#author xiaoweige#todo: ip -- > ingredient or ingredient -- > ip #todo: get the ip ...

  4. 参加360前端星计划总结(二)--HTML&CSS

    HTML学习手册(英文版)html:the living standard 重要知识点 文档声明的作用a. 指定html的文档标准和版本b. 告诉浏览器渲染模式,有怪异模式(较为古老的模式,不写文档声 ...

  5. 通过yum安装MySQL5.7.4

    1,进入yum的repo文件夹 cd /etc/yum.repos.d 2,mysql主页已经提供了centos等系统需要的rpm文件,直接去主页下载. 我用的centos6.5,选择Red Hat ...

  6. RNA-seq简单处理流程

    RNA_seq pipline RNA_seq pipline PeRl 2018年3月7日 首先说明一下我做RNA-seq处理流程的文件树格式: RNA-seq/ data/ GRCh38.gtf ...

  7. Web 前端性能优化相关内容解析

    Web 前端性能优化相关内容,来源于<Google官方网页载入速度检测工具PageSpeed Insights 使用教程>一文中PageSpeed Insights 的相关说明.大家可以对 ...

  8. C#调整图片亮度和对比度

    BitmapSource bitmap = null; ; ; private void SetBrightness(int degree) { degree = degree * / ; Write ...

  9. oracle中查找锁定状态的用户

    SQL> desc dba_users;desc dba_users; 名前 NULL? 型 ----------------------------------------- -------- ...

  10. PHP 注释规范

    注释在写代码的过程中非常重要,好的注释能让你的代码读起来更轻松,在写代码的时候一定要注意注释的规范. php里面常见的几种注释方式: 1.文件头的注释,介绍文件名,功能以及作者版本号等信息 /** * ...