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

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.xdnf.cn/news/10647.html

相关文章:

  • LangGraph framework
  • 《Linux 包管理实战手册:RPM 精准操作与 YUM 自动化部署从入门到精通》
  • 软件测评师 第9章 基于质量特性的测试与评价 笔记
  • SQL 中的 `CASE WHEN` 如何使用?
  • CUDA与OpenGL混合编程图形渲染
  • 【Python 算法零基础 4.排序 ⑦ 桶排序】
  • 【算法训练营Day05】哈希表part1
  • 《软件项目管理》第二章(项目准备与启动)期末周复习总结笔记
  • uniapp中view标签使用范围
  • Kotlin 中companion object {} 什么时候触发
  • C语言:内存函数
  • 前端面试高频问题通关指南--通用性问题
  • Python----目标检测(使用YOLO 模型进行线程安全推理和流媒体源)
  • SQL: 窗口滑动(Sliding Window)
  • 数学建模期末速成 最短路径
  • 23. Merge k Sorted Lists
  • Alist Win 基本用法
  • JavaSE知识总结(集合篇) ~个人笔记以及不断思考~持续更新
  • Python中使用pandas
  • C++ list代码练习、set基础概念、set对象创建、set大小操作
  • SQL 窗口函数深度解析:ROW_NUMBER 实战指南
  • volatile,synchronized,原子操作实现原理,缓存一致性协议
  • LabVIEW准分子激光器智能控制系统
  • 35.x64汇编写法(二)
  • Elasticsearch 读写流程深度解析
  • JAVA中的注解和泛型
  • 用 Whisper 打破沉默:AI 语音技术如何重塑无障碍沟通方式?
  • Mybatis框架各配置文件主要内容详解(二)
  • 神经网络与深度学习(第二章)
  • 数字化转型全场景安全解析:从产品到管理的防线构建与实施要点