div2题目题解:Divisors of Two Integers(桶记录数值的普通思维题)

题目:

我这个题目直接复制粘贴的,所以会有显示上的问题;
B. Divisors of Two Integers
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
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
inputCopy
10
10 2 8 1 2 4 1 20 4 5
outputCopy
20 8

题意:

题意就是:然后给出一个由两个数a,b的所有因子组成的序列,然后让你求出这两个数,我们用桶记录这个序列里面的数就好了,然后拿出最大的那个数一定就是ab其中的一个,这个最大数取出所有因子去桶那里抵消一下就好了。

完整代码实现:

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <climits>
#include <queue>
#include <stack>
#include <map>
//鬼畜头文件
using namespace std;
#define INF 0x3f3f3f3f
#define ULL unsigned long long
#define LL long long
//鬼畜define
int n;
int tong[10001];
int main()
{
 
	scanf("%d",&n);
	fill(tong,tong+n,0);
	int _MAX=-1;
	long long sum=1;
	for(int time=0;time<n;time++)
	{
		int num;
		scanf("%d",&num);
		tong[num]++;
		if(_MAX==-1||_MAX<num)_MAX=num;
	}
	//input finished;
	int time;
	for(time=1;time*time<_MAX;time++)
	{
		if(_MAX%time==0){tong[time]--;tong[_MAX/time]--;}
	}
	if(time*time==_MAX)tong[time]--;
	int ans=1;
	for(time=_MAX;time>=1;time--)
	{
		if(tong[time]==1){ans=time;break;}
	}
	printf("%d %d\n",_MAX,ans);
 
    return 0;
}
发布了25 篇原创文章 · 获赞 2 · 访问量 1923
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 书香水墨 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览