题库练习 Difference Array
← 上一题 下一题 →

A15190 | Difference Array

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

You are given an array $a$ consisting of $n$ non-negative integers. It is guaranteed that $a$ is sorted from small to large.

For each operation, we generate a new array $b_i=a_{i+1}-a_{i}$ for $1 \le i < n$ . Then we sort $b$ from small to large, replace $a$ with $b$ , and decrease $n$ by $1$ .

After performing $n-1$ operations, $n$ becomes $1$ . You need to output the only integer in array $a$ (that is to say, you need to output $a_1$ ).

输入格式

The input consists of multiple test cases. The first line contains a single integer $t$ ( $1\le t\le 10^4$ ) — the number of test cases. The description of the test cases follows.

The first line of each test case contains one integer $n$ ( $2\le n\le 10^5$ ) — the length of the array $a$ .

The second line contains $n$ integers $a_1,a_2,\dots,a_n$ ( $0\le a_1\le \ldots\le a_n \le 5\cdot 10^5$ ) — the array $a$ .

It is guaranteed that the sum of $n$ over all test cases does not exceed $2.5\cdot 10^5$ , and the sum of $a_n$ over all test cases does not exceed $5\cdot 10^5$ .

输出格式

For each test case, output the answer on a new line.

输入输出样例

输入 #1
5
3
1 10 100
4
4 8 9 13
5
0 0 0 8 13
6
2 4 8 16 32 64
7
0 0 0 0 0 0 0
输出 #1
81
3
1
2
0
C++ 编辑器
输入
输出