CF2234A.Euclid, Sequence and Two Numbers

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

We define a Euclid algorithm sequence of length kk (k≥2k \geq 2) for two positive integers x≥yx \geq y as the following sequence of positive integers:

  • a1,a2,…,aka_1, a_2, \ldots, a_k, where a1=xa_1 = x, a2=ya_2 = y, and for any ii (1≤i≤k−21 \leq i \leq k - 2), the equality ai+2=(ai mod ai+1)a_{i + 2} = (a_i \bmod a_{i + 1}) holds∗^{\text{∗}}.

For example, for x=13,y=8,k=4x = 13, y = 8, k = 4, the corresponding Euclid algorithm sequence is a=[13,8,5,3]a = [13, 8, 5, 3]. (a3=13 mod 8=5a_3 = 13 \bmod 8 = 5, a4=8 mod 5=3a_4 = 8 \bmod 5 = 3).

You are given a sequence b1,b2,…,bnb_1, b_2, \ldots, b_n. You need to determine whether it is possible to permute its elements so that it becomes a Euclid algorithm sequence for some two positive integers x≥yx \geq y.

∗^{\text{∗}}x mod yx \bmod y denotes the remainder when xx is divided by yy.

我们定义两个正整数 x≥yx \geq y 的长度为 kk(k≥2k \geq 2)的欧几里得算法序列如下所示的正整数序列:

  • a1,a2,…,aka_1, a_2, \ldots, a_k,其中 a1=xa_1 = x,a2=ya_2 = y,且对任意 ii(1≤i≤k−21 \leq i \leq k - 2),均满足 ai+2=(ai mod ai+1)a_{i + 2} = (a_i \bmod a_{i + 1})。

例如,当 x=13x = 13、y=8y = 8、k=4k = 4 时,对应的欧几里得算法序列为 a=[13,8,5,3]a = [13, 8, 5, 3]。(a3=13 mod 8=5a_3 = 13 \bmod 8 = 5,a4=8 mod 5=3a_4 = 8 \bmod 5 = 3)

给定一个序列 b1,b2,…,bnb_1, b_2, \ldots, b_n。你需要判断:是否可能重排该序列的元素,使其成为某个正整数对 x≥yx \geq y 对应的欧几里得算法序列。

∗^{\text{∗}}x mod yx \bmod y 表示 xx 除以 yy 所得的余数。

输入格式

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 an integer nn (2≤n≤1002 \leq n \leq 100) — the size of the sequence.

The second line of each test case contains nn integers b1,b2,…,bnb_1, b_2, \ldots, b_n (1≤bi≤1091 \leq b_i \leq 10^9) — the sequence bb.

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

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

每个测试用例的第二行包含 nn 个整数 b1,b2,…,bnb_1, b_2, \ldots, b_n(1≤bi≤1091 \leq b_i \leq 10^9)—— 序列 bb。

输出格式

For each test case, if it is possible to permute the elements of sequence bb so that there exists a suitable pair of positive integers x≥yx \geq y, output x,yx, y on a separate line. Otherwise, output −1-1 on a separate line.

If there are several suitable pairs x,yx, y, you may output any of them.

对于每个测试用例,如果可以对序列 bb 的元素进行重排,使得存在一对满足条件的正整数 x≥yx \geq y,则在单独一行输出 x,yx, y;否则,在单独一行输出 −1-1。

如果存在多对满足条件的 x,yx, y,则可输出其中任意一对。

输入输出样例

  • 输入#1

    6
    2
    1 1
    2
    1 2
    4
    1 2 3 4
    3
    6 4 2
    4
    3 8 13 5
    3
    1 1 1

    输出#1

    1 1
    2 1
    -1
    6 4
    13 8
    -1

说明/提示

In the first test case, the pair (1,11, 1) is suitable: for x=1,y=1,k=2x = 1, y = 1, k = 2, a1=x=1,a2=y=1a_1 = x = 1, a_2 = y = 1, and the sequence a=[1,1]=ba = [1, 1] = b is obtained.

In the third test case, it can be shown that no suitable pair (x,yx, y) exists.

In the fourth test case, the pair (6,46, 4) is suitable: for x=6,y=4,k=3x = 6, y = 4, k = 3, a1=x=6,a2=y=4,a3=(a1 mod a2)=(6 mod 4)=2a_1 = x = 6, a_2 = y = 4, a_3 = (a_1 \bmod a_2) = (6 \bmod 4) = 2, and the sequence a=[6,4,2]=ba = [6, 4, 2] = b is obtained.

在第一个测试用例中,数对 (1,1)(1, 1) 是可行的:当 x=1,y=1,k=2x = 1, y = 1, k = 2 时,有 a1=x=1,a2=y=1a_1 = x = 1, a_2 = y = 1,从而得到序列 a=[1,1]=ba = [1, 1] = b。

在第三个测试用例中,可以证明不存在可行的数对 (x,y)(x, y)。

在第四个测试用例中,数对 (6,4)(6, 4) 是可行的:当 x=6,y=4,k=3x = 6, y = 4, k = 3 时,有 a1=x=6,a2=y=4,a3=(a1 mod a2)=(6 mod 4)=2a_1 = x = 6, a_2 = y = 4, a_3 = (a_1 \bmod a_2) = (6 \bmod 4) = 2,从而得到序列 a=[6,4,2]=ba = [6, 4, 2] = b。

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

首页