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
按照回文子串的奇偶分类讨论,分别计算其对答案的贡献,然后奇偶分别进行求和. 推导出来,化简一下……发现奇数也好,偶数也好,都可以拆成一个等比数列求和,以及一个可以错位相减的数列求和. 然后用高中数学知 ...
随机推荐
- ORACLE环境变量定义
export在linux的bash中可以理解为设置环境变量.设置后能够被当前的shell及子shell使用. 这些变量的含义有一些有意义,可以查看相应的文档,我给你解释一些我知道的: ORACLE_H ...
- FromData获取表单数据
一般想要不刷新页面提交数据时,可以使用ajax提交.如果数据量不大可以自己写json数据用ajax提交到后台服务,但是数据量多且需要动态添加数据时,自己写json格式数据就有点麻烦了,这时候就需要Fo ...
- DSB
Linux day01 计算机硬件知识整理 作业要求:整理博客,内容如下 编程语言的作用及与操作系统和硬件的关系 应用程序->操作系统->硬件 cpu->内存->磁盘 cpu与 ...
- laravel 里面结合关联查询 的when()用法
Laravel 5.6 里面的when用法: $name = $request->get('name'); //活动标题 $start_time = $request->get('star ...
- python(6):Scipy之pandas
pandas下面的数据结构是Series , DataFrame 在字典中, key 与 value对应, 但是key value 不是独立的, 但是在Series 中index 与value 是独立 ...
- java----Java的栈,堆,代码,静态存储区的存储顺序和位置
转载:https://blog.csdn.net/zhangbaoanhadoop/article/details/82193497
- uva11827 处理下输入
/*0.012s*/ #include<cstdio> #include<algorithm> using namespace std; ], n; int gcd(int a ...
- Django入门基础详解
本次使用django版本2.1.2 安装django 安装最新版本 pip install django 安装指定版本 pip install django==1.10.1 查看本机django版本 ...
- tomcat和server安装和操作
servers的创建 最后一步:ctrl+s
- C#学习-属性是对字段的扩展
属性是对字段的扩展. 根据面向对象语言的封装思想,字段最好设为private,因为这样可以防止客户端直接对字段进行篡改,从而保证了内部成员的完整性. 于是为了访问类中的私有字段,C#提供了属性这种机制 ...