CF2234A.Euclid, Sequence and Two Numbers
入门
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
We define a Euclid algorithm sequence of length k (k≥2) for two positive integers x≥y as the following sequence of positive integers:
- a1,a2,…,ak, where a1=x, a2=y, and for any i (1≤i≤k−2), the equality ai+2=(aimodai+1) holds∗.
For example, for x=13,y=8,k=4, the corresponding Euclid algorithm sequence is a=[13,8,5,3]. (a3=13mod8=5, a4=8mod5=3).
You are given a sequence b1,b2,…,bn. 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≥y.
∗xmody denotes the remainder when x is divided by y.
我们定义两个正整数 x≥y 的长度为 k(k≥2)的欧几里得算法序列如下所示的正整数序列:
- a1,a2,…,ak,其中 a1=x,a2=y,且对任意 i(1≤i≤k−2),均满足 ai+2=(aimodai+1)。
例如,当 x=13、y=8、k=4 时,对应的欧几里得算法序列为 a=[13,8,5,3]。(a3=13mod8=5,a4=8mod5=3)
给定一个序列 b1,b2,…,bn。你需要判断:是否可能重排该序列的元素,使其成为某个正整数对 x≥y 对应的欧几里得算法序列。
∗xmody 表示 x 除以 y 所得的余数。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤500). The description of the test cases follows.
The first line of each test case contains an integer n (2≤n≤100) — the size of the sequence.
The second line of each test case contains n integers b1,b2,…,bn (1≤bi≤109) — the sequence b.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤500)。随后是各测试用例的描述。
每个测试用例的第一行包含一个整数 n(2≤n≤100)—— 序列的长度。
每个测试用例的第二行包含 n 个整数 b1,b2,…,bn(1≤bi≤109)—— 序列 b。
输出格式
For each test case, if it is possible to permute the elements of sequence b so that there exists a suitable pair of positive integers x≥y, output x,y on a separate line. Otherwise, output −1 on a separate line.
If there are several suitable pairs x,y, you may output any of them.
对于每个测试用例,如果可以对序列 b 的元素进行重排,使得存在一对满足条件的正整数 x≥y,则在单独一行输出 x,y;否则,在单独一行输出 −1。
如果存在多对满足条件的 x,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,1) is suitable: for x=1,y=1,k=2, a1=x=1,a2=y=1, and the sequence a=[1,1]=b is obtained.
In the third test case, it can be shown that no suitable pair (x,y) exists.
In the fourth test case, the pair (6,4) is suitable: for x=6,y=4,k=3, a1=x=6,a2=y=4,a3=(a1moda2)=(6mod4)=2, and the sequence a=[6,4,2]=b is obtained.
在第一个测试用例中,数对 (1,1) 是可行的:当 x=1,y=1,k=2 时,有 a1=x=1,a2=y=1,从而得到序列 a=[1,1]=b。
在第三个测试用例中,可以证明不存在可行的数对 (x,y)。
在第四个测试用例中,数对 (6,4) 是可行的:当 x=6,y=4,k=3 时,有 a1=x=6,a2=y=4,a3=(a1moda2)=(6mod4)=2,从而得到序列 a=[6,4,2]=b。
输入解题思路,AI测评打分。不知道怎么写?