CF1909B.Make Almost Equal With Mod

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

xi - Solar Storm

⠀

You are given an array a1,a2,…,ana_1, a_2, \dots, a_n of distinct positive integers. You have to do the following operation exactly once:

  • choose a positive integer kk;
  • for each ii from 11 to nn, replace aia_i with ai mod k†a_i \text{ mod } k^\dagger.

Find a value of kk such that 1≤k≤10181 \leq k \leq 10^{18} and the array a1,a2,…,ana_1, a_2, \dots, a_n contains exactly 22 distinct values at the end of the operation. It can be shown that, under the constraints of the problem, at least one such kk always exists. If there are multiple solutions, you can print any of them.

†^\dagger a mod ba \text{ mod } b denotes the remainder after dividing aa by bb. For example:

  • 7 mod 3=17 \text{ mod } 3=1 since 7=3⋅2+17 = 3 \cdot 2 + 1
  • 15 mod 4=315 \text{ mod } 4=3 since 15=4⋅3+315 = 4 \cdot 3 + 3
  • 21 mod 1=021 \text{ mod } 1=0 since 21=21⋅1+021 = 21 \cdot 1 + 0

xi - 太阳风暴

⠀

给定一个由 nn 个互不相同的正整数构成的数组 a1,a2,…,ana_1, a_2, \dots, a_n。你必须恰好执行一次如下操作:

  • 选择一个正整数 kk;
  • 对每个 ii(从 11 到 nn),将 aia_i 替换为 ai mod k†a_i \text{ mod } k^\dagger。

请找出一个满足 1≤k≤10181 \leq k \leq 10^{18} 的 kk,使得操作结束后数组 a1,a2,…,ana_1, a_2, \dots, a_n 中恰好包含 2 个不同的值。可以证明,在本题约束条件下,这样的 kk 总是存在的。如果存在多个解,输出任意一个即可。

†^\dagger a mod ba \text{ mod } b 表示 aa 除以 bb 后所得的余数。例如:

  • 7 mod 3=17 \text{ mod } 3=1,因为 7=3⋅2+17 = 3 \cdot 2 + 1
  • 15 mod 4=315 \text{ mod } 4=3,因为 15=4⋅3+315 = 4 \cdot 3 + 3
  • 21 mod 1=021 \text{ mod } 1=0,因为 21=21⋅1+021 = 21 \cdot 1 + 0

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤5001 \le t \le 500). The description of the test cases follows.

The first line of each test case contains a single integer nn (2≤n≤1002 \le n \le 100) — the length of the array aa.

The second line of each test case contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤10171 \le a_i \le 10^{17}) — the initial state of the array. It is guaranteed that all the aia_i are distinct.

Note that there are no constraints on the sum of nn over all test cases.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤5001 \le t \le 500)。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(2≤n≤1002 \le n \le 100)—— 数组 aa 的长度。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤10171 \le a_i \le 10^{17})—— 数组的初始状态。保证所有 aia_i 互不相同。

注意:对所有测试用例的 nn 之和没有限制。

输出格式

For each test case, output a single integer: a value of kk (1≤k≤10181 \leq k \leq 10^{18}) such that the array a1,a2,…,ana_1, a_2, \dots, a_n contains exactly 22 distinct values at the end of the operation.

对于每个测试用例,输出一个整数:满足条件的 kk 值(1≤k≤10181 \leq k \leq 10^{18}),使得在执行完操作后,数组 a1,a2,…,ana_1, a_2, \dots, a_n 中恰好包含 22 个不同的值。

输入输出样例

  • 输入#1

    5
    4
    8 15 22 30
    5
    60 90 98 120 308
    6
    328 769 541 986 215 734
    5
    1000 2000 7000 11000 16000
    2
    2 1

    输出#1

    7
    30
    3
    5000
    1000000000000000000

说明/提示

In the first test case, you can choose k=7k = 7. The array becomes [8 mod 7,15 mod 7,22 mod 7,30 mod 7]=[1,1,1,2][8 \text{ mod } 7, 15 \text{ mod } 7, 22 \text{ mod } 7, 30 \text{ mod } 7] = [1, 1, 1, 2], which contains exactly 22 distinct values (1,2{1, 2}).

In the second test case, you can choose k=30k = 30. The array becomes [0,0,8,0,8][0, 0, 8, 0, 8], which contains exactly 22 distinct values (0,8{0, 8}). Note that choosing k=10k = 10 would also be a valid solution.

In the last test case, you can choose k=1018k = 10^{18}. The array becomes [2,1][2, 1], which contains exactly 22 distinct values (1,2{1, 2}). Note that choosing k=1018+1k = 10^{18} + 1 would not be valid, because 1≤k≤10181 \leq k \leq 10^{18} must be true.

在第一个测试用例中,你可以选择 k=7k = 7。此时数组变为 [8 mod 7,15 mod 7,22 mod 7,30 mod 7]=[1,1,1,2][8 \text{ mod } 7, 15 \text{ mod } 7, 22 \text{ mod } 7, 30 \text{ mod } 7] = [1, 1, 1, 2],恰好包含 22 个不同的值({1,2}\{1, 2\})。

在第二个测试用例中,你可以选择 k=30k = 30。此时数组变为 [0,0,8,0,8][0, 0, 8, 0, 8],恰好包含 22 个不同的值({0,8}\{0, 8\})。注意,选择 k=10k = 10 同样是一个合法的解。

在最后一个测试用例中,你可以选择 k=1018k = 10^{18}。此时数组变为 [2,1][2, 1],恰好包含 22 个不同的值({1,2}\{1, 2\})。注意,选择 k=1018+1k = 10^{18} + 1 是不合法的,因为必须满足 1≤k≤10181 \leq k \leq 10^{18}。

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

首页