特别水的题,可惜我还是不会做
Recently you have received two positive integer numbers x and y. You forgot them, but you remembered a shuffled list containing all divisors of x (including 1 and x) and all divisors of y (including 1 and y). If d is a divisor of both numbers x and y at the same time, there are two occurrences of d in the list.
For example, if x=4 and y=6 then the given list can be any permutation of the list [1,2,4,1,2,3,6]. Some of the possible lists are: [1,1,2,4,6,3,2], [4,6,1,1,2,3,2] or [1,6,3,2,4,1,2].
Your problem is to restore suitable positive integer numbers x and y 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 x and y.
Input
The first line contains one integer n (2≤n≤128) — the number of divisors of x and y.
The second line of the input contains n integers d1,d2,…,dn (1≤di≤104), where di is either divisor of x or divisor of y. If a number is divisor of both numbers x and y then there are two copies of this number in the list.
Output
Print two positive integer numbers x and y — such numbers that merged list of their divisors is the permutation of the given list of integers. It is guaranteed that the answer exists.
Example
Input
10
10 2 8 1 2 4 1 20 4 5
Output
20 8
//////////////////////////////
////
大致意思是这样的,给出一连串的数字,让你找出两个数,使得其他的数都是这两个数的因数!!!
//////////////
思路就更简单了:
首先最大的那个数肯定是一个,所以只需要找出另一个就可以了,另一个数就是不能被第一个数整除的最大的那个数,并且第二个数不和与它相邻的数相等。
再找第二个数的时候,可以再定义一个数组,遍历给出的数,如果是第一个数的因数且不和相邻的数相等,就把第二个数组对应的值设为1;其他的设为0;那么第二个就找到了。
////////////
AC 代码
#include<stdio.h>
#include<iostream>
#include<stack>
#include<vector>
#include<map>
#include<string.h>
#include<set>
#include<algorithm>
#include<list>
#include<queue>
#include<string>
using namespace std;
int main()
{
int n, a, b, x[100010], d[100010];
while (scanf("%d", &n) != EOF)
{
for (int i = 0; i < n; i++)
{
cin >> x[i];
}
sort(x, x + n);
a = x[n - 1];
b = 0;
for (int i = 0; i < n; i++)
{
if (a%x[i] == 0 && x[i] != x[i + 1])
{
d[i] = 1;
}
else
d[i] = 0;
}
for (int i = n - 2; i >= 0; i--)
{
if (!d[i])
{
b = x[i];
break;
}
}
cout << a << " " << b << endl;
}
return 0;
}