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
4
1 3 3 7
YES
1 1
1 3
3 1
1 7
5
3 1 3 3 7
NO
6
9 10 9 10 9 10
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[200005]; bool cmp(E a,E b) { return a.val < b.val; } int ll[200005]; int rr[200005]; int main() { scanf("%d",&n); for(int i=1; i<=n; i++) { scanf("%d",&e[i].val); e[i].index = i; } sort(e+1,e+1+n,cmp); int cnt = 0; int flag = 0; for(int i=1; i<=n; i++) { int l=i,r=i; while(r+1<=n && e[r].val == e[r+1].val) r++; for(int j=1; j*j<=e[i].val; j++) { if(e[i].val % j == 0) { 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 = 1; break; } i = r; } if(flag)printf("NO\n"); else { printf("YES\n"); for(int i=1;i<=n;i++) { printf("%d %d\n",ll[i],rr[i]); } } }