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);
      }
    }
  }
}
目录
打赏
0
0
0
0
8
分享
相关文章
Docker 核心概念深度解析:探索容器、镜像和仓库在Docker生态系统中的重要作用和 应用
Docker 核心概念深度解析:探索容器、镜像和仓库在Docker生态系统中的重要作用和 应用
1137 0
智能运维,由你定义:SAE自定义日志与监控解决方案
SAE(Serverless应用引擎)是阿里云推出的全托管PaaS平台,致力于简化微服务应用开发与管理。为满足用户对可观测性和运维能力的更高需求,SAE引入Sidecar容器技术,实现日志采集、监控指标收集等功能扩展,且无需修改主应用代码。通过共享资源模式和独立资源模式,SAE平衡了资源灵活性与隔离性。同时,提供全链路运维能力,确保应用稳定性。未来,SAE将持续优化,支持更多场景,助力用户高效用云。
基于jeecgboot的flowable复杂会签加用户选择流程实现
基于jeecgboot的flowable复杂会签加用户选择流程实现
279 2
Tauri框架:使用Rust构建轻量级桌面应用
Tauri是一个用Rust构建的开源框架,用于创建轻量、安全且高效的跨平台桌面应用,结合Rust与Web技术(HTML/CSS/JS)。它遵循最小权限原则,仅在必要时调用OS API。Tauri架构包括Rust后端、Web前端、Tauri API和包装器。通过`cargo tauri init`可创建新项目,Rust后端处理系统交互,前端负责UI,两者通过Tauri API通信。Tauri支持自定义API、集成前端框架、资源管理、自动更新、系统集成和安全配置。此外,Tauri拥有插件系统和丰富的扩展能力,提供调试和测试工具,并有性能优化建议。
656 4
分布式锁工具:Redisson,很强!
分布式锁工具:Redisson,很强!
466 1
几行代码轻松复现druid连接泄露的BUG之PhyTimeout
几行代码轻松复现druid连接泄露的BUG之PhyTimeout
408 0
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等

登录插画

登录以查看您的控制台资源

管理云资源
状态一览
快捷访问