当前位置: 首页 > news >正文

A. We Need the Zero

time limit per test

1 second

memory limit per test

256 megabytes

There is an array aa consisting of non-negative integers. You can choose an integer xx and denote bi=ai⊕xbi=ai⊕x for all 1≤i≤n1≤i≤n, where ⊕⊕ denotes the bitwise XOR operation. Is it possible to choose such a number xx that the value of the expression b1⊕b2⊕…⊕bnb1⊕b2⊕…⊕bn equals 00?

It can be shown that if a valid number xx exists, then there also exists xx such that (0≤x<280≤x<28).

Input

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤10001≤t≤1000). The description of the test cases follows.

The first line of the test case contains one integer nn (1≤n≤1031≤n≤103) — the length of the array aa.

The second line of the test case contains nn integers — array aa (0≤ai<280≤ai<28).

It is guaranteed that the sum of nn over all test cases does not exceed 103103.

Output

For each set test case, print the integer xx (0≤x<280≤x<28) if it exists, or −1−1 otherwise.

Example

Input

Copy

 

5

3

1 2 5

3

1 2 3

4

0 1 2 3

4

1 2 2 3

1

1

Output

Copy

6
0
3
-1
1

Note

In the first test case, after applying the operation with the number 66 the array bb becomes [7,4,3][7,4,3], 7⊕4⊕3=07⊕4⊕3=0.

There are other answers in the third test case, such as the number 00.

解题说明:此题是一道数学题,题目意思是是否存在一个数x使 a1^x^a2^x^a3^x...an^x=0。首先求出a1^a2..^an的值,然后判断n的奇偶性,奇数则就是该值,因为两个相同的数相与为0.如果n为偶数,则偶数个x本来相与就为0,只能判断a1^a2..^an结果是否为0,如果不是0,则不存在这样的值。

#include <stdio.h>int main()
{int t;scanf("%d", &t);while (t--) {int j, n, a, acc_xor = 0;scanf("%d", &n);for (j = 0; j < n; ++j){scanf("%d", &a);acc_xor ^= a;}if (n & 1){printf("%d\n", acc_xor);}else if (acc_xor == 0) {printf("0\n");}else{printf("-1\n");}}return 0;
}

http://www.lqws.cn/news/75727.html

相关文章:

  • NX869NX874美光固态颗粒NX877NX883
  • Vortex GPGPU的github流程跑通与功能模块波形探索(四)
  • FFmpeg移植教程(linux平台)
  • RSCUcaller
  • 12.1 GUI 事件处理
  • 《 C++ 点滴漫谈: 四十 》文本的艺术:C++ 正则表达式的高效应用之道
  • 前端高频面试题2:JavaScript/TypeScript
  • 迈向分布式智能:解析MCP到A2A的通信范式迁移
  • 第十二节:第四部分:集合框架:List系列集合:LinkedList集合的底层原理、特有方法、栈、队列
  • 【华为云Astro Zero】组装设备管理页面开发(图形拖拽 + 脚本绑定)
  • Ubuntu上进行VS Code的配置
  • STM32G4 电机外设篇(四)DAC输出电流波形 + CAN通讯
  • 16QAM在瑞利信道下的性能仿真:从理论到实践的完整解析(附完整代码)
  • 审计- 3- 风险评估:内部控制
  • NVMe协议简介之AXI总线更新
  • MySQL锁机制
  • Linux 脚本文件编辑(vim)
  • 【接口测试】基础知识
  • 使用 HTML + JavaScript 实现图片裁剪上传功能
  • PCIe—TS1/TS2 之Polling.Configuration (二)
  • 【位运算】只出现⼀次的数字 II(medium)
  • world quant教程学习
  • 第二章支线五 ·CSS炼金续章:变量与暗黑主题术
  • 前端八股之Vue
  • 手机归属地查询接口如何用Java调用?
  • 1.文件操作相关的库
  • 阿里云国际站,如何通过代理商邀请的链接注册账号
  • 600+纯CSS加载动画一键获取指南
  • 我爱学算法之—— 前缀和(上)
  • 回测效率提升500%!khQuant打板策略回测性能深度剖析——基于miniQMT的回测系统深度优化【AI量化第29篇】