♥codeforces 627A-XOR Equation【数学】

痛定思痛。 2022-08-21 04:26 245阅读 0赞

A. XOR Equation

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

Examples

Input

  1. 9 5

Output

  1. 4

Input

  1. 3 3

Output

  1. 2

Input

  1. 5 2

Output

  1. 0

Note

In the first sample, we have the following solutions: (2, 7), (3, 6), (6, 3), (7, 2).

In the second sample, the only solutions are (1, 2) and (2, 1).

  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<algorithm>
  4. #define LL long long
  5. using namespace std;
  6. int main()
  7. {
  8. LL a,b;
  9. while(scanf("%I64d%I64d",&a,&b)!=EOF)
  10. {
  11. LL i,j;
  12. LL ans=0;
  13. if((a-b)>=0&&(a-b)%2==0)
  14. {
  15. LL wc=(a-b)/2;
  16. int cut=0;
  17. bool flag=true;
  18. if(a==b)
  19. ans-=2;
  20. while(b)
  21. {
  22. if(b&1)
  23. {
  24. cut++;
  25. if(wc&1)
  26. {
  27. flag=false;
  28. }
  29. }
  30. if(!flag)
  31. {
  32. break;
  33. }
  34. b/=2,wc/=2;
  35. }
  36. if(!flag) ans = 0;
  37. else ans += (1LL<<cut);
  38. }
  39. printf("%I64d\n",ans);
  40. }
  41. return 0;
  42. }

发表评论

表情:
评论列表 (有 0 条评论,245人围观)

还没有评论,来说两句吧...

相关阅读