Masquerade strikes back Gym - 101911D (数学)

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 aibi=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 (1n21051≤n≤2⋅105 ) — the number of lost testcases.

Second line contains nn space-separated integers c1,c2,,cnc1,c2,…,cn (1ci1071≤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 aibi=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[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]);
        }
    }
}
View Code

 

转载于:https://www.cnblogs.com/iwannabe/p/10559761.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值