CF2179C.Blackslex and Number Theory

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Blackslex worked too hard and started dreaming about numbers. Solve the following task from his dreams.

You are given an array a1,a2,…,ana_1, a_2, \ldots, a_n.

In one operation you choose an index ii (1≤i≤n1 \le i \le n) and an integer xx which is at least kk and set $$ a_i := a_i \bmod x, $$ where u mod vu \bmod v denotes the remainder of dividing uu by vv.

Your goal is to make all elements of the array identical. Among all positive integers kk, determine the maximum kk for which there exists a finite sequence of the above operations that makes all array elements equal.

Blackslex 工作过于辛苦,开始梦见数字。请解决他梦中出现的以下问题。

给定一个数组 a1,a2,…,ana_1, a_2, \ldots, a_n。

在一次操作中,你选择一个下标 ii(1≤i≤n1 \le i \le n)和一个不小于 kk 的整数 xx,并执行

a_i:=a_ibmodx,a\_i := a\_i \\bmod x,

其中 u mod vu \bmod v 表示 uu 除以 vv 所得的余数。

你的目标是使数组的所有元素相等。在所有正整数 kk 中,求最大的 kk,使得存在有限次上述操作,能将数组所有元素变为相同值。

输入格式

The first line contains a single integer tt (1≤t≤1041 \le t \le 10^4) — the number of test cases.

The first line of each test case contains a single integer nn (2≤n≤2⋅1052 \le n \le 2 \cdot 10^5).

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤1091 \le a_i \le 10^9, all values of aa are distinct).

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052 \cdot 10^5.

第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)—— 表示测试用例的数量。

每个测试用例的第一行包含一个整数 nn(2≤n≤2⋅1052 \le n \le 2 \cdot 10^5)。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤1091 \le a_i \le 10^9,且所有 aia_i 的值互不相同)。

保证所有测试用例的 nn 值之和不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case, print a single integer — the maximum positive integer kk such that it is possible to make all elements of the array identical using any number of operations with moduli xx restricted to k≤xk \le x.

对于每个测试用例,输出一个整数——即最大的正整数 kk,使得存在若干次操作(每次操作所用模数 xx 满足 k≤xk \le x),能够使数组中所有元素变为相同值。

输入输出样例

  • 输入#1

    3
    3
    5 7 9
    2
    2 3
    7
    11 74 5 22 52 97 82

    输出#1

    5
    2
    6

输入解题思路,AI测评打分。不知道怎么写?

首页