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.

Input

The first line contains one integer nn (2≤n≤1282≤n≤128) — the number of divisors of xxand yy.

The second line of the input contains nn integers d1,d2,…,dnd1,d2,…,dn (1≤di≤1041≤di≤104), where didi is either divisor of xx or divisor of yy. If a number is divisor of both numbers xxand yy then there are two copies of this number in the list.

Output

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.

Example

Input
10
10 2 8 1 2 4 1 20 4 5
Output
20 8

题意:
给定一个数组,这个数组包含了两个正整数a和b的所有因子,包括1和a,b,如果x同为a和b的因子,那么数组中x出现两次。
让求出a和b的数值。
思路:首先对数组进行排序,那么最大值一定是我们a和b中的一个(原因自行思考)。那么我们最大值是a。
然后我们暴力的把a的所有因子都求出来,从数组中删除一次,然后剩下的数组中的最大值就是我们要找的b。
细节见代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define db(x) cout<<"== [ "<<x<<" ] =="<<endl;
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD){ll ans=;while(b){if(b%)ans=ans*a%MOD;a=a*a%MOD;b/=;}return ans;}
inline void getInt(int* p);
const int maxn=;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
ll n;
ll a[maxn];
int main()
{
gbtb;
cin>>n;
map<ll,ll> m;
repd(i,,n)
{
cin>>a[i];
m[a[i]]++;
}
sort(a+,a++n); ll x=1ll;
ll y=1ll;
y=a[n]; for(ll i=;i<=y;i++)
{
if(y%i==)
m[i]--;
}
for(ll i=;i>=;i--)
{
if(m[i]==)
{
x=i;
break;
}
}
cout<<x<<" "<<y;
return ;
} inline void getInt(int* p) {
char ch;
do {
ch = getchar();
} while (ch == ' ' || ch == '\n');
if (ch == '-') {
*p = -(getchar() - '');
while ((ch = getchar()) >= '' && ch <= '') {
*p = *p * - ch + '';
}
}
else {
*p = ch - '';
while ((ch = getchar()) >= '' && ch <= '') {
*p = *p * + ch - '';
}
}
}

Divisors of Two Integers CodeForces - 1108B (数学+思维)的更多相关文章

  1. B. Tell Your World(几何数学 + 思维)

    B. Tell Your World time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  2. 程序设计中的数学思维函数总结(代码以C#为例)

    最近以C#为例,学习了程序设计基础,其中涉及到一些数学思维,我们可以巧妙的将这些逻辑问题转换为代码,交给计算机运算. 现将经常会使用到的基础函数做一总结,供大家分享.自己备用. 1.判断一个数是否为奇 ...

  3. PJ考试可能会用到的数学思维题选讲-自学教程-自学笔记

    PJ考试可能会用到的数学思维题选讲 by Pleiades_Antares 是学弟学妹的讲义--然后一部分题目是我弄的一部分来源于洛谷用户@ 普及组的一些数学思维题,所以可能有点菜咯别怪我 OI中的数 ...

  4. B. Divisors of Two Integers

    B. Divisors of Two Integers time limit per test 1 second memory limit per test 256 megabytes input s ...

  5. UVa10025 The ? 1 ? 2 ? ... ? n = k problem 数学思维+规律

    UVa10025 ? 1 ? 2 ? ... ? n = k problem The problem Given the following formula, one can set operator ...

  6. Codeforces Round #272 (Div. 2) C. Dreamoon and Sums (数学 思维)

    题目链接 这个题取模的时候挺坑的!!! 题意:div(x , b) / mod(x , b) = k( 1 <= k <= a).求x的和 分析: 我们知道mod(x % b)的取值范围为 ...

  7. Codeforces Round #555 (Div. 3) D. N Problems During K Days 【数学思维】

    一 题面 D. N Problems During K Days 二 分析 对于这题,刚开始我就是陷入了对公式的执着,企图用公式直接确定第一个数,然后试着去找序列.经过思考和手动模拟后发现是很难保证正 ...

  8. Sum of Consecutive Integers LightOJ - 1278(推公式 数学思维)

    原文地址:https://blog.csdn.net/qq_37632935/article/details/79465213 给你一个数n(n<=10^14),然后问n能用几个连续的数表示; ...

  9. Minimum Integer CodeForces - 1101A (思维+公式)

    You are given qq queries in the following form: Given three integers lili, riri and didi, find minim ...

随机推荐

  1. Django之--通过MVC架构的html模板展示Hello World!

    上一篇:Django之--网页展示Hello World! 初步说明了如何使用Django来显示hello world,本文略微进阶下使用html模板来展示hello world~ 首先在mysite ...

  2. Linux进程核心调度器之主调度器schedule--Linux进程的管理与调度(十九)

    主调度器 在内核中的许多地方, 如果要将CPU分配给与当前活动进程不同的另一个进程, 都会直接调用主调度器函数schedule, 从系统调用返回后, 内核也会检查当前进程是否设置了重调度标志TLF_N ...

  3. 使用Navicat for Mysql连接mysql服务器

    使用Navicat for Mysql连接mysql服务器 在windows上用Navicat for Mysql 连接装在虚拟机Ubuntu上的mysql服务器时出现的问题的解决方案. Navica ...

  4. 快速启动神器 Wox

    wox(快速启动程序) wox官网:http://www.wox.one/ 下载wox:https://github.com/Wox-launcher/Wox/releases wox插件库:http ...

  5. 028实现strStr()

    #pragma once #include "000库函数.h" /*********************自解**************/ //使用算法中的find 12ms ...

  6. Java虚拟机(Java Virtual Machine)

    JVM(Java Virtual Machine),Java虚机机,是JDK最底层的东西.只要能将源代码编译成字节码(.class)文件,就可以由JVM在不同平台上解释成机器指令来执行.所以,Java ...

  7. FastJSON、Gson和Jackson性能对比

    Java处理JSON数据有三个比较流行的类库FastJSON.Gson和Jackson.本文将测试这三个类库在JSON序列化和反序列化的方面表现,主要测试JSON序列化和反序列化的速度.为了防止由于内 ...

  8. node基础—process对象(管理进程)

    process对象概述 process对象是一个全局对象,可以在任何地方都能访问到他,通过这个对象提供的属性和方法,使我们可以对当前运行的程序的进程进行访问和控制 process 对象是一个 glob ...

  9. centos7下安装docker(14安装docker machine)

    之前我们做的实验都是在一个host上面的,其实在真正的环境中有多个host,容器在这些host上面启动,运行,停止和销毁,相关容器会通过网络相互通信,无论他们是否运行在相同的host上面. 对于这种歌 ...

  10. UVA690-Pipeline Scheduling(dfs+二进制压缩状态)

    Problem UVA690-Pipeline Scheduling Accept:142  Submit:1905 Time Limit: 3000 mSec  Problem Descriptio ...