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 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[]; 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 (数学)的更多相关文章
- Masquerade strikes back Gym - 101911D(补题) 数学
https://vjudge.net/problem/Gym-101911D 具体思路: 对于每一个数,假设当前的数是10 分解 4次,首先 1 10 这是一对,然后下一次就记录 10 1,这样的话直 ...
- gym 101911
A. Coffee Break 题意:每天有m小时,你喝咖啡需要花一小时,你想在n个时刻都喝过一次咖啡,老板规定连续喝咖啡的间隔必须是d以上,求最少需要多少天才能喝够n次咖啡,并输出每个时刻第几天喝. ...
- 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 排序之后优先队 ...
- 【 Gym - 101124E 】Dance Party (数学)
BUPT2017 wintertraining(15) #4G Gym - 101124 E.Dance Party 题意 有c种颜色,每个颜色最多分配给两个人,有M个男士,F个女士,求至少一对男士同 ...
- Codeforces Gym 100002 D"Decoding Task" 数学
Problem D"Decoding Task" Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com ...
- 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 ...
- 【Gym - 101124A】The Baguette Master (数学,几何)
BUPT2017 wintertraining(15) #4F Gym - 101124A 题意 给定画框宽度,画的四边和一个对角线长度,求画框外沿周长. 题解 过顶点做画框的垂线,每个角都得到两个全 ...
- 【 Gym - 101138F 】GukiZ Height (数学)
BUPT2017 wintertraining(15) #4 C Gym - 101138F 题意 初始高度0,目标值h,第i天目标值会下降i,当前高度会改变a[i%n],求高度不小于目标值的最早的时 ...
- 【推导】【数学期望】Gym - 101237D - Short Enough Task
按照回文子串的奇偶分类讨论,分别计算其对答案的贡献,然后奇偶分别进行求和. 推导出来,化简一下……发现奇数也好,偶数也好,都可以拆成一个等比数列求和,以及一个可以错位相减的数列求和. 然后用高中数学知 ...
随机推荐
- mysql服务器没有响应
第一步删除c:\windowns下面的my.ini(可以先改成其它的名字也行) 第二步打开对应安装目录下\mysql\bin\winmysqladmin.exe 输入用户名 和密码(也可以忽略此步) ...
- day 13 装饰器
装饰器基础 装饰器的目的是为了给被装饰 对象,增加新功能,或者说增加某种能力 在程序中工具就是函数 如此一来,装饰器指的就是一个函数,被装饰着也是一个函数 总结;装饰器就是用一个函数去拓展另外一个已存 ...
- 页面初始化的js函数要放在最最最最最最最前边!否则没效果
简单说一下这个情况,html的页面的各部分都是动态渲染的,所以头部的某些个样式调用函数需要在页面初始化的时候被加载,这个我也是知道的,结果后边代码敲着敲着,就把这个事儿给忘了,然后启动项目的时候,页面 ...
- axure--中继器
*****中继器-repeater*****1.结构:类似于MVC(增删查改)1)中继器数据集:可包括图片.文字.网址(页面)(右键添加,列名尽量使用英 文或拼音) 2)中继器格式:横向.纵向(是否换 ...
- java提取出一个字符串里面的Double类型数字
String str="hh\n1\n22\n798.809\n0.89\n"; String regex="\\d+(?:\\.\\d+)?" ...
- Ubuntu 更改屏幕分辨率
安装完Ubuntu后发现分辨率不合适,平时习惯了看小一点的文字,所以搜了一下修改屏幕分辨率的命令,具体操作如下: 1.先用 xrandr 命令查看一下当前系统支持的分辨率 wayde@wayde-Al ...
- Django中模板使用
第一步:配置 1.在工程中创建模板目录templates. 2.在settings.py配置文件中修改TEMPLATES配置项的DIRS值:TEMPLATES = [ { 'BACKEND': 'dj ...
- 泛微云桥e-birdge之金蝶云之家集成配置手册
最近在配置金蝶云之家与泛微ecology的打通,没有看官方文档,直接配置,一直配置不通,看了官方文档后知道了少配置参数了,转载一下,省得四处去找了. 泛微云桥e-birdge之金蝶云之家集成配置手册 ...
- Tomcat使用https
# 用JDK自带的Keytool生成keystore文件keytool -genkey -alias tomcat -keyalg RSA -keypass Envisi0n -storepass E ...
- Spark的Streaming和Spark的SQL简单入门学习
1.Spark Streaming是什么? a.Spark Streaming是什么? Spark Streaming类似于Apache Storm,用于流式数据的处理.根据其官方文档介绍,Spark ...