\(\\\)

\(Description\)


\(T\) 组询问,每次给出一个 \(a\),求方程

\[a-(a\oplus x)-x=0
\]

的方案数。

  • \(T\le 10^3,a\le 2^{30}\)

\(\\\)

\(Solution\)


我菜又被巨佬 \(Diss\) 了......

考场 \(NC\) 问了爷们半懂不懂的就过了......

移项,得

\[a=(a\oplus x)+x
\]

然后注意到满足这个性质的 \(x\) ,在二进制表示下一定是 \(a\) 的子集。

因为\(a\oplus x\)表示的是两者不交的部分的并集,再加上\(x\)表示的就是两个集合的并再加上 \(x\) 这一集合中 \(a\) 集合不包含的部分。

要是想要这个东西等于 \(a\) ,当且仅当 \(x\) 集合中不在 \(a\) 集合中的部分为空集。

然后就是统计 \(a\) 子集的个数。

显然一开始答案为 \(1\) ,遇到二进制位的一个 \(1\) 就答案个数就会翻倍。

\(\\\)

\(Code\)


#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define R register
#define gc getchar
using namespace std;
typedef long long ll; inline ll rd(){
ll x=0; bool f=0; char c=gc();
while(!isdigit(c)){if(c=='-')f=1;c=gc();}
while(isdigit(c)){x=(x<<1)+(x<<3)+(c^48);c=gc();}
return f?-x:x;
} ll x,ans=1; void work(){
ans=1ll;
x=rd();
while(x){
if((x&1ll)==1ll) ans<<=1;
x>>=1;
}
printf("%I64d\n",ans);
} int main(){
ll t=rd();
while(t--) work();
return 0;
}

[ CodeForces 1064 B ] Equations of Mathematical Magic的更多相关文章

  1. CF 1064B Equations of Mathematical Magic(思维规律)

    Description Colossal! — exclaimed Hawk-nose. — A programmer! That's exactly what we are looking for. ...

  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. cf#516B. Equations of Mathematical Magic(二进制,位运算)

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

  5. Codeforces Round #335 (Div. 2) A. Magic Spheres 水题

    A. Magic Spheres Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.codeforces.com/contest/606/ ...

  6. Codeforces Round #443 (Div. 1) D. Magic Breeding 位运算

    D. Magic Breeding link http://codeforces.com/contest/878/problem/D description Nikita and Sasha play ...

  7. Codeforces Round #350 (Div. 2) D1. Magic Powder - 1 二分

    D1. Magic Powder - 1 题目连接: http://www.codeforces.com/contest/670/problem/D1 Description This problem ...

  8. 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 ...

  9. codeforces 495B. Modular Equations 解题报告

    题目链接:http://codeforces.com/problemset/problem/495/B 题目意思:给出两个非负整数a,b,求出符合这个等式      的所有x,并输出 x 的数量,如果 ...

随机推荐

  1. Java 输入一个正整数,按蛇形打印。

    参考博客:    http://yangyingming.com/article/371/ //输入一个正整数n(n<=30),输出n所对应的蛇形矩阵.举两个例子: //n=10时,蛇形矩阵为: ...

  2. operamasks-omGrid的使用

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="personTab.aspx ...

  3. Nginx/Spring:增加上传文件尺寸限制

    Nginx: 1. vi /etc/nginx/nginx.config 2. 在server中增加如下行 # set client body size to 20M # client_max_bod ...

  4. ThinkPHP3.2 点击看不清刷新验证码

    欢迎使用Markdown编辑器写博客 baidu了一下.发现没有可用的源码,自己想了想,以下的方法可行. <!DOCTYPE html> <html> <head> ...

  5. Java之旅(1)—Class类

    看到Class的时候,我们是不是会一下子想到我们敲代码中的class呢?此Class非彼class,这里讲的Class类实际上就是java类的统称,我们能够将其称之为抽象的类不是详细的一个类的名字. ...

  6. Linux挂载新盘

    Linux 系统挂载数据盘 1.查看数据盘 使用“fdisk-l”命令查看 2. 对数据盘进行分区 执行“fdisk /dev/sdb”命令,对数据盘进行分区: 输入“n”,“p”“1”,两次回车,“ ...

  7. C语言事实上不简单:数组与指针

    之前在写C的时候,没怎么留意数组.就这么定义一个.然后颠来倒去的使用即可了.只是后来碰到了点问题.解决后决定写这么一篇博客,数组离不开指针.索性就放一起好了. 如今我定义了一个数组:int cc[10 ...

  8. POJ 3370 Halloween treats(抽屉原理)

    Halloween treats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 6631   Accepted: 2448 ...

  9. Office 如何打印彩色照片能取得较好的效果

    1 如下图所示,随便打开一个照片,点击打印,纸张大小,质量,纸张类型如下所示.   2 这样打印的设置还是不够的,因为"高级光面纸"或者类似的纸张类型,会把色彩浓度调大,相对于普通 ...

  10. hdu oj 1285 确定比赛名次

    hdu oj 1285 确定比赛名次 题目: 确定比赛名次 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K ...