Quite often the jury of Saratov SU use the problem "Masquerade" in different practice sessions before the contest. This problem is quite easy — all you need is to print the product of two integers which were read from the input stream.

As usual, the jury had prepared this problem once again. The jury had nn testcases, the ii -th testcase was a pair of positive integers aiai and bibi , both integers didn't exceed 107107 . All testcases were pairwise distinct.

Unfortunately, something went wrong. Due to hardware issues all testcases have disappeared. All that the jury were able to restore are the number of testcases nn and the answers to these testcases, i. e. a sequence of nn numbers c1,c2,…,cnc1,c2,…,cn , such that ai⋅bi=ciai⋅bi=ci .

The jury ask you to help them. Can you provide any possible testset? Remember that all testcases were distinct and all numbers in each testcase were positive integers and didn't exceed 107107 .

Input

First line contains one insteger nn (1≤n≤2⋅1051≤n≤2⋅105 ) — the number of lost testcases.

Second line contains nn space-separated integers c1,c2,…,cnc1,c2,…,cn (1≤ci≤1071≤ci≤107 ) — the answers to the testcases.

Output

If there is no such testset, print NO.

Otherwise, print YES in first line. Then print nn more lines, the ii -th of them should contain two space separated positive integers aiai and bibi not exceeding 107107 . All pairs (ai,bi)(ai,bi) must be distinct, and, for each i∈[1,n]i∈[1,n] , the condition ai⋅bi=ciai⋅bi=ci must be met.

Examples

Input
4
1 3 3 7
Output
YES
1 1
1 3
3 1
1 7
Input
5
3 1 3 3 7
Output
NO
Input
6
9 10 9 10 9 10
Output
YES
1 9
1 10
3 3
5 2
9 1
2 5

Note

In the first example one of the possible testsets is (a1=1a1=1 , b1=1b1=1 ), (a2=1a2=1 , b2=3b2=3 ), (a3=3a3=3 , b3=1b3=1 ), (a4=1a4=1 , b4=7b4=7 ).

In the second example a testset consisting of distinct tests doesn't exist.

题意:给出n个数,让你将每个数都表示成两个数相乘,但是不能重复,(1*3和3*1不算重复)可以就输出结果,否则输出NO

思路:对于给出的数里,相同的数我们可以一起处理,即可以先排序,然相同的数挨在一起,我们可以统计其个数,然后在这个数开方范围内寻找因子。最后统计该数出现的个数和式子数时候满足要求,即式子是否足够多。

#include<bits/stdc++.h>
using namespace std; int n; struct E
{
int val;
int index;
} e[]; bool cmp(E a,E b)
{
return a.val < b.val;
} int ll[];
int rr[];
int main()
{
scanf("%d",&n);
for(int i=; i<=n; i++)
{
scanf("%d",&e[i].val);
e[i].index = i;
}
sort(e+,e++n,cmp);
int cnt = ;
int flag = ;
for(int i=; i<=n; i++)
{
int l=i,r=i;
while(r+<=n && e[r].val == e[r+].val)
r++;
for(int j=; j*j<=e[i].val; j++)
{
if(e[i].val % j == )
{
ll[e[l].index] = j;
rr[e[l].index] = e[i].val / j;
l++;
if(l > r)break;
if(j * j != e[i].val)
{
ll[e[l].index] = e[i].val / j;
rr[e[l].index] = j;
l++;
if(l > r)break;
}
}
}
if(l <= r)
{
flag = ;
break;
}
i = r;
}
if(flag)printf("NO\n");
else
{
printf("YES\n");
for(int i=;i<=n;i++)
{
printf("%d %d\n",ll[i],rr[i]);
}
}
}

Masquerade strikes back Gym - 101911D (数学)的更多相关文章

  1. Masquerade strikes back Gym - 101911D(补题) 数学

    https://vjudge.net/problem/Gym-101911D 具体思路: 对于每一个数,假设当前的数是10 分解 4次,首先 1 10 这是一对,然后下一次就记录 10 1,这样的话直 ...

  2. gym 101911

    A. Coffee Break 题意:每天有m小时,你喝咖啡需要花一小时,你想在n个时刻都喝过一次咖啡,老板规定连续喝咖啡的间隔必须是d以上,求最少需要多少天才能喝够n次咖啡,并输出每个时刻第几天喝. ...

  3. 2018-2019 ACM-ICPC, NEERC, Southern Subregional Contest, Qualification Stage(11/12)

    2018-2019 ACM-ICPC, NEERC, Southern Subregional Contest, Qualification Stage A. Coffee Break 排序之后优先队 ...

  4. 【 Gym - 101124E 】Dance Party (数学)

    BUPT2017 wintertraining(15) #4G Gym - 101124 E.Dance Party 题意 有c种颜色,每个颜色最多分配给两个人,有M个男士,F个女士,求至少一对男士同 ...

  5. Codeforces Gym 100002 D"Decoding Task" 数学

    Problem D"Decoding Task" Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com ...

  6. Gym 101194E / UVALive 7901 - Ice Cream Tower - [数学+long double][2016 EC-Final Problem E]

    题目链接: http://codeforces.com/gym/101194/attachments https://icpcarchive.ecs.baylor.edu/index.php?opti ...

  7. 【Gym - 101124A】The Baguette Master (数学,几何)

    BUPT2017 wintertraining(15) #4F Gym - 101124A 题意 给定画框宽度,画的四边和一个对角线长度,求画框外沿周长. 题解 过顶点做画框的垂线,每个角都得到两个全 ...

  8. 【 Gym - 101138F 】GukiZ Height (数学)

    BUPT2017 wintertraining(15) #4 C Gym - 101138F 题意 初始高度0,目标值h,第i天目标值会下降i,当前高度会改变a[i%n],求高度不小于目标值的最早的时 ...

  9. 【推导】【数学期望】Gym - 101237D - Short Enough Task

    按照回文子串的奇偶分类讨论,分别计算其对答案的贡献,然后奇偶分别进行求和. 推导出来,化简一下……发现奇数也好,偶数也好,都可以拆成一个等比数列求和,以及一个可以错位相减的数列求和. 然后用高中数学知 ...

随机推荐

  1. js跳转页面(转)

    <span id="tiao">3</span><a href="javascript:countDown"></a& ...

  2. Swift 学习- 05 -- 集合类型

    // 集合类型 // swift 提供 Arrays , Sets 和 Dictionaries 三种基本的集合类型用来存储数据 , 数组(Arrays) 是有序数据的集, 集合(Sets)是无序无重 ...

  3. 《精通Oracle SQL(第2版)》PDF

    一:下载途径 二:图书图样 三:目录 第1章 SQL核心 1.1 SQL语言 1.2 数据库的接口 1.3 SQL*Plus回顾 1.3.1 连接到数据库 1.3.2 配置SQL*Plus环境 1.3 ...

  4. linux 批量进行:解压缩某一类压缩文件类型的文件

    1: 编写脚本 [oracle@oracle oracle]$ vim unzip.sh ziphome=/u01/app/oracle ziplist=`du -a $ziphome |grep ' ...

  5. 【linux】ssh无法root免密解决

    在设置了root的私钥和公钥,添加authorized_keys,修改文件权限为600后,用root账号 ssh localhost结果失败了,还是要密码. 解决: vim /etc/ssh/sshd ...

  6. git 注意事项

    1,用户凭证 github的两种url地址 http      ssh :由于Git和Github交互操作可能会很频繁,那么一定少了用户授权的操作,为了防止每次操作重复输入用户名和密码,Git提供了两 ...

  7. VisualSVN Server如何安装和使用

    首先来下载和搭建SVN服务器. 现在Subversion已经迁移到apache网站上了,下载地址: http://subversion.apache.org/packages.html 这是二进制文件 ...

  8. python 利用split读取文本文件中每一行的数字并保存至相应文件夹

    import re from numpy import * def getStr(file_path,file_path1): fp = open(file_path, 'r') op = open( ...

  9. Python模块之sys模块

    sys模块是与Python解释器交互的一个接口 有如下方法 sys.argv   命令行参数的一个列表,第一个参数为程序本身的路径 sys.exit(n)  退出程序,正常退出exit(0) ,异常退 ...

  10. 创建Python虚拟环境

    以window为例: 安装完python后, 打开cmd, 命令行输入: pip install virtualenv ,安装过程见截图 进入你想安装虚拟环境的目录, 命令行输入: virtualen ...