C. XOR Equation

题目连接:

http://www.codeforces.com/contest/635/problem/C

Description

Two positive integers a and b have a sum of s and a bitwise XOR of x. How many possible values are there for the ordered pair (a, b)?

Input

The first line of the input contains two integers s and x (2 ≤ s ≤ 1012, 0 ≤ x ≤ 1012), the sum and bitwise xor of the pair of positive integers, respectively.

Output

Print a single integer, the number of solutions to the given conditions. If no solutions exist, print 0.

Sample Input

9 5

Sample Output

4

Hint

题意

给你两个数的和,以及两个数的异或结果,问你有多少个数对a,b满足要求

题解:

首先你要知道 a+b = a&b*2 + a^b,这个东西是递归加法的定义

所以你就知道了a&b和a^b,然后根据这两个东西对于数字的每一位进行讨论就好了

如果a^b = 1,那么a&b必须等于0,否则肯定不对嘛,这时候,ai=1 bi=0,ai=0 bi=1有两种选择

如果a^b = 0,那么a&b = ai = bi,只有一种选择

所以答案就是2的a^b中1的个数次方。当然,最后还得判一判s==x的情况,这种情况得把0的情况给剖去。

代码

#include<bits/stdc++.h>
using namespace std; long long s,x;
int flag = 0;
int main()
{
cin>>s>>x;
if(s==x)flag = 1;
s-=x;
if(s%2==1)return puts("0");
s/=2;
long long ans = 1;
for(int i=0;i<60;i++)
{
int p1 = (s>>i)&1;
int p2 = (x>>i)&1;
if(p2==1&&p1==1)return puts("0");
if(p2==1)ans*=2;
}
if(flag)ans-=2;
cout<<ans<<endl;
}

8VC Venture Cup 2016 - Final Round (Div. 2 Edition) C. XOR Equation 数学的更多相关文章

  1. 8VC Venture Cup 2016 - Final Round (Div. 2 Edition)

    暴力 A - Orchestra import java.io.*; import java.util.*; public class Main { public static void main(S ...

  2. 8VC Venture Cup 2016 - Final Round (Div. 1 Edition) E - Preorder Test 树形dp

    E - Preorder Test 思路:想到二分答案了之后就不难啦, 对于每个答案用树形dp取check, 如果二分的值是val, dp[ i ]表示 i 这棵子树答案不低于val的可以访问的 最多 ...

  3. 8VC Venture Cup 2016 - Final Round (Div. 2 Edition) A

    A. Orchestra time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  4. 8VC Venture Cup 2016 - Final Round (Div. 2 Edition) D. Factory Repairs 树状数组

    D. Factory Repairs 题目连接: http://www.codeforces.com/contest/635/problem/D Description A factory produ ...

  5. 8VC Venture Cup 2016 - Final Round (Div. 2 Edition)B. sland Puzzle 水题

    B. sland Puzzle 题目连接: http://www.codeforces.com/contest/635/problem/B Description A remote island ch ...

  6. 8VC Venture Cup 2016 - Final Round (Div. 2 Edition) A. Orchestra 水题

    A. Orchestra 题目连接: http://www.codeforces.com/contest/635/problem/A Description Paul is at the orches ...

  7. Codeforces Round #393 (Div. 2) (8VC Venture Cup 2017 - Final Round Div. 2 Edition) E - Nikita and stack 线段树好题

    http://codeforces.com/contest/760/problem/E 题目大意:现在对栈有m个操作,但是顺序是乱的,现在每输入一个操作要求你输出当前的栈顶, 注意,已有操作要按它们的 ...

  8. Codeforces Round #393 (Div. 2) (8VC Venture Cup 2017 - Final Round Div. 2 Edition) D - Travel Card

    D - Travel Card 思路:dp,类似于单调队列优化. 其实可以写的更简单... #include<bits/stdc++.h> #define LL long long #de ...

  9. Codeforces Round #393 (Div. 2) (8VC Venture Cup 2017 - Final Round Div. 2 Edition)A 水 B 二分 C并查集

    A. Petr and a calendar time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

随机推荐

  1. skb管理函数之skb_clone、pskb_copy、skb_copy

    skb_clone--只复制skb描述符本身,如果只修改skb描述符则使用该函数克隆: pskb_copy--复制skb描述符+线性数据区域(包括skb_shared_info),如果需要修改描述符以 ...

  2. 【Android framework】am命令启动Activity流程

    源码基于Android 4.4.   am start -W -n com.dfp.test/.TEstActivity -W:等目标Activity启动后才返回 -n:用于设置Intent的Comp ...

  3. java===java基础学习(3)---数据类型转换,运算符级别,枚举类型

    数据类型转换: 有的时候,程序需要将数据类型,比如 int + float ,结果是float, 这里的int就被转换为float类型,属于合法转换. Java中的合法转换如下图: 红色表示无信息丢失 ...

  4. 蓝屏代码0X0000007B可能是SATA mode问题

    Win7蓝屏代码0X0000007B可能是硬盘模式的问题,我进入BIOS把SATA的mode从Enhanced改为Compatible(及IDE兼容模式)结果系统可以顺利启动没有问题.       从 ...

  5. 【模板】SPOJ FACT0 大数分解 miller-rabin & pollard-rho

    http://www.spoj.com/problems/FACT0/en/ 给一个小于1e15的数,将他分解. miller-rabin & pollard-rho模板 #include & ...

  6. HDU 5627 Clarke and MST &意义下最大生成树 贪心

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5627 题意:Bestcoder的一道题,让你求&意义下的最大生成树. 解法: 贪心,我们从高位 ...

  7. 文字顺时针旋转90度(纵向)&古诗词排版

    1.文字旋转90度 width: 100px; height: 200px; line-height: 100px; text-align: center; writing-mode: vertica ...

  8. Python——format()/str.format()函数

    格式化输出,除了类似于C语言的格式化输出外,还有str.format()方法,Python内建的format()函数,允许用户将待输出值以参数的形式,调用format()函数,在Python交互式sh ...

  9. 2017百度春招<度度熊买帽子的问题>

    题目: 度度熊想去商场买一顶帽子,商场里有N顶帽子,有些帽子的价格可能相同.度度熊想买一顶价格第三便宜的帽子,问第三便宜的帽子价格是多少? 数组中找到第三小的数字  注意边界条件 用STL中的set来 ...

  10. [PAT] 1141 PAT Ranking of Institutions(25 分)

    After each PAT, the PAT Center will announce the ranking of institutions based on their students' pe ...