CF1108B.Divisors of Two Integers

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Recently you have received two positive integer numbers xx and yy. You forgot them, but you remembered a shuffled list containing all divisors of xx (including 11 and xx) and all divisors of yy (including 11 and yy). If dd is a divisor of both numbers xx and yy at the same time, there are two occurrences of dd in the list.

For example, if x=4x=4 and y=6y=6 then the given list can be any permutation of the list [1,2,4,1,2,3,6][1, 2, 4, 1, 2, 3, 6]. Some of the possible lists are: [1,1,2,4,6,3,2][1, 1, 2, 4, 6, 3, 2], [4,6,1,1,2,3,2][4, 6, 1, 1, 2, 3, 2] or [1,6,3,2,4,1,2][1, 6, 3, 2, 4, 1, 2].

Your problem is to restore suitable positive integer numbers xx and yy that would yield the same list of divisors (possibly in different order).

It is guaranteed that the answer exists, i.e. the given list of divisors corresponds to some positive integers xx and yy.

最近,你收到了两个正整数 xxyy。你忘记了它们的具体值,但还记得一个打乱顺序的列表,该列表包含 xx 的所有正因数(包括 11xx)以及 yy 的所有正因数(包括 11yy)。如果某个数 dd 同时是 xxyy 的公因数,则该数 dd 在列表中会出现两次。

例如,若 x=4x=4y=6y=6,则所给列表可以是 [1,2,4,1,2,3,6][1, 2, 4, 1, 2, 3, 6] 的任意一个排列。一些可能的列表包括:[1,1,2,4,6,3,2][1, 1, 2, 4, 6, 3, 2][4,6,1,1,2,3,2][4, 6, 1, 1, 2, 3, 2][1,6,3,2,4,1,2][1, 6, 3, 2, 4, 1, 2]

你的任务是恢复出一对合适的正整数 xxyy,使得它们的所有因数(按上述规则重复公因数后)组成的列表与给定列表一致(顺序可不同)。

题目保证答案存在,即所给的因数列表确实对应某对正整数 xxyy

输入格式

The first line contains one integer nn (2n1282 \le n \le 128) — the number of divisors of xx and yy.

The second line of the input contains nn integers d1,d2,,dnd_1, d_2, \dots, d_n (1di1041 \le d_i \le 10^4), where did_i is either divisor of xx or divisor of yy. If a number is divisor of both numbers xx and yy then there are two copies of this number in the list.

第一行包含一个整数 nn2n1282 \le n \le 128)—— 即 xxyy 的约数个数之和。

输入的第二行包含 nn 个整数 d1,d2,,dnd_1, d_2, \dots, d_n1di1041 \le d_i \le 10^4),其中每个 did_i 要么是 xx 的约数,要么是 yy 的约数。若某个数同时是 xxyy 的约数,则该数在列表中会出现两次。

输出格式

Print two positive integer numbers xx and yy — such numbers that merged list of their divisors is the permutation of the given list of integers. It is guaranteed that the answer exists.

输出两个正整数 xxyy,使得它们的所有约数合并后的列表是给定整数列表的一个排列。保证答案存在。

输入输出样例

  • 输入#1

    10
    10 2 8 1 2 4 1 20 4 5

    输出#1

    20 8

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

首页