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. Linux 入门记录:二、Linux 文件系统基本结构

    一.树状目录结构 Linux 文件系统是一个倒置的单根树状结构.文件系统的根为"/":文件名严格区分大小写:路径使用"/"分割(Windows 中使用" ...

  2. c#使用selenium+Chromedriver参数配置

    using System; //添加selenium的引用 using OpenQA.Selenium.PhantomJS; using OpenQA.Selenium.Chrome; using O ...

  3. Oracle 获取ddl语句

    --得到所有表空间的ddl语句 SELECT DBMS_METADATA.GET_DDL('TABLESPACE', TS.tablespace_name)FROM DBA_TABLESPACES T ...

  4. python代码实现dijkstra算法

    求解从1到6的最短路径. python代码实现:(以A-F代表1-6) # Dijkstra算法需要三张散列表和一个存储列表用于记录处理过的节点,如下: processed = [] def buil ...

  5. 【python】时间戳、字典列表排序

    记录一下昨天学到的知识: 一.文件相关 文件追加:f = open("fname","a")    文件不存在时创建 二.时间戳相关 http://www.jb ...

  6. 《java并发编程实战》读书笔记10--显示锁Lock,轮询、定时、读写锁

    第13章 显示锁 终于看到了这本书的最后一本分,呼呼呼,真不容易.其实说实在的,我不喜欢半途而废,有其开始,就一定要有结束,否则的话就感觉哪里乖乖的. java5.0之前,在协调对共享对象的访问时可以 ...

  7. electron调用C#应用程序实现串口通信

    最近转入零售行业开发了一系列产品,包含便利店收银软件.会员系统.供应链系统.为了追赶潮流,收银软件使用了electron平台开发,界面效果.开发效率确实不错:但是涉及到串口通讯时遇到了麻烦,elect ...

  8. CentOS 6.7下配置 yum 安装 Nginx

    CentOS 6.7下配置 yum 安装 Nginx. 转载:http://www.linuxidc.com/Linux/2016-07/133283.htm 第一步,在/etc/yum.repos. ...

  9. sonar rule

    bug类型: 1.".equals()" should not be used to test the values of "Atomic" classes.  ...

  10. BotBuilder Nodejs示例查看

    关于Bot Framework知识,可以参考<Nodejs Bot学习> 本文是根据bot framework官方示例<https://github.com/Microsoft/Bo ...