Codeforces Round #742 (Div. 2)

简介: Codeforces Round #742 (Div. 2)

B. MEXor Mixup

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output


Alice gave Bob two integers aa and bb (a>0a>0 and b≥0b≥0). Being a curious boy, Bob wrote down an array of non-negative integers with MEXMEX value of all elements equal to aa and XORXOR value of all elements equal to bb.


What is the shortest possible length of the array Bob wrote?


Recall that the MEXMEX (Minimum EXcluded) of an array is the minimum non-negative integer that does not belong to the array and the XORXOR of an array is the bitwise XOR of all the elements of the array.


Input


The input consists of multiple test cases. The first line contains an integer tt (1≤t≤5⋅1041≤t≤5⋅104) — the number of test cases. The description of the test cases follows.


The only line of each test case contains two integers aa and bb (1≤a≤3⋅1051≤a≤3⋅105; 0≤b≤3⋅1050≤b≤3⋅105) — the MEXMEX and XORXOR of the array, respectively.


Output


For each test case, output one (positive) integer — the length of the shortest array with MEXMEX aa and XORXOR bb. We can show that such an array always exists.


Example


input


Copy

5

1 1

2 1

2 0

1 10000

2 10000


output


Copy

3

2

3

2

3


Note

In the first test case, one of the shortest arrays with MEXMEX 11 and XORXOR 11 is [0,2020,2021][0,2020,2021].


In the second test case, one of the shortest arrays with MEXMEX 22 and XORXOR 11 is [0,1][0,1].

It can be shown that these arrays are the shortest arrays possible.


直接贴代码,分类讨论就行了、


#include <bits/stdc++.h>
using namespace std;
#define ll long long
 signed  main() {
  ll t;
  cin >> t;
  int g[300001];
  for (int i = 1; i <= 300000; i++) {
    g[i] = g[i - 1] ^ i;
  }
  while (t--) {
    ll n, m;
    cin >> n;
    cin >> m;
    ll ans = n;
    if (g[n - 1] == m) {
      printf("%lld\n", ans);
      continue;
    } else {
      if (m == 0 && g[n - 1] != n) {
        printf("%lld\n", ans + 1);
        continue;
      }
      if ((g[n - 1]^n) == m) {
        printf("%lld\n", ans + 2);
      }
      else {
        printf("%lld\n", ans + 1);
      }
    }
  }
}
相关文章
|
Web App开发 搜索推荐 NoSQL
如何搭建一个集成导航与在线工具的个性化浏览器私有书签(附详细搭建教程)
在这个信息爆炸的时代,我们都希望拥有一个能够轻松解决多端、多浏览器的收藏和笔记同步问题的神奇工具。Mtab书签正是为此而设计的顶级应用。它将基础导航、记事本、在线小工具和多端同步集于一身,为用户提供了更便利的网络浏览体验,并解决了多端同步的烦恼。
719 0
如何搭建一个集成导航与在线工具的个性化浏览器私有书签(附详细搭建教程)
|
缓存 NoSQL 前端开发
【Redis技术专区】「实战案例」谈谈使用Redis缓存时高效的批量删除的几种方案
【Redis技术专区】「实战案例」谈谈使用Redis缓存时高效的批量删除的几种方案
586 0
|
Web App开发 JavaScript 前端开发
JavaScript高级进阶(更新中)-javascript-gao-ji-jin-jie--geng-xin-zhong-(一)
JavaScript高级进阶(更新中)-javascript-gao-ji-jin-jie--geng-xin-zhong-
297 0
|
缓存 IDE 编译器
鲲鹏系列一: DevKit代码迁移工具技术要点总结
处理器所支持的指令集不同,意味着开发者可能需要对代码进行跨平台的迁移。通常,代码迁移是件复杂又繁琐的工作,需要花费开发者大量精力对软件包、源代码、依赖库文件进行人工分析、检查和识别,手动修正不同指令集之间的相关差异,这些差异主要涉及语法、指令、函数和库文件支持情况。
1116 0
鲲鹏系列一: DevKit代码迁移工具技术要点总结
|
网络协议 虚拟化 Windows
玩转神龙服务器的Hyper-V虚拟化网络配置之 保持虚拟机网络连通性
相信已经有同学已经在神龙上部署了Hyper-V了。又可以随心所欲的创建VM玩耍了。但是关于Hyper-V虚拟机的网络配置,相信还有一些同学没有玩过。 首先,我们来简单介绍下Hyper-v的三种虚拟交换机的类型: * **外部交换机** 这种交换机允许虚拟机访问到真实的物理网络。虚拟机之间和Hyper-V Server (这里是我们的神龙物理机)也可以相互访问。 ![imag
2575 0
|
数据格式 XML API
AIR打开系统文件目录
在写webgame的资源管理器的时候,想加一个功能,就是在解析版本xml时,想打开目录查看里面的文件。 air里弹出选择文件对话框倒简单,搜索了一番没找到相应的解决方案,后来使用英文进行搜索,在老外的论坛中找到了两个解决方案: 1、使用openWithDefaultApplication 2、...
1181 0
|
2天前
|
监控 网络协议 算法
2026年起SSL证书有效期逐年缩短:企业如何避免“续期风暴”!
SSL证书有效期将从2026年起分三阶段逐步缩短至47天,人工续期难以为继。阿里云“WoSign SSL证书+自动化服务”,支持域名监控、自动托管、云产品/服务器一键部署及智能提醒,助力企业高效应对高频续期挑战。
8077 2
|
11天前
|
域名解析 人工智能 Linux
|
19天前
|
人工智能
Google 提示「所在地区不可用」?进不去 Antigravity 或 Gemini,先查账号这个设置
进不去 Antigravity 或 Gemini,提示所在地区不可用?三步查清 Google 账号关联地区、官方更正表单理由选法与改区注意事项。
10264 13
Google 提示「所在地区不可用」?进不去 Antigravity 或 Gemini,先查账号这个设置