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个数,每个数c对应输出一对数a,b,a*b=c;这些对数不能重复((1,3)和(3,1)不算)
根据一个数的因子都可以由有限个质因子相乘得来,注意的是c存在大于sqrt©的质因子最多只有一个。所以只需要标记sqrt(1e7)+1内的质数就够用了
一开始不会处理一个数是第几个数(按输入的顺序),因为直接用数组的话要1e7很大了,后来学了vector<pair<int, int> > arr(n), ans(n);才把一个数和他的序号绑在一起了。
最后排一下序号,就可以找到每种数字的因子了,用一个动态数组存起来,所以需要先排序,不排序的话还得想办法标记。
ac代码

#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
const int N = sqrt(1e7)+1;
vector<int>q,times,temp;
bool prime[N];
int len;
vector<int> p;
void prime2()
{for (int i = 2; i < N; i++) prime[i] = true;for (int i = 2; i < N; i++) {if (prime[i]) p.push_back(i);for (int j = 1; j*i <N ; j++) {prime[i*j]=false;}}len=p.size();
}
void asd(int x)//求出x的所有因子并存起来
{times.clear();int m,s=1;times.push_back(1);for (int i = 0; i < len && p[i] <= x; i++){m=1;if (x % p[i] == 0){while (x% p[i] == 0){x /= p[i];m*=p[i];q.push_back(m);}int length=times.size();int len2=q.size();for(int k=0;k<len2;k++){for(int j=0;j<length;j++)times.push_back(q[k]*times[j]);                 q.pop_back();}}}if(x>1)//大于sqrt(最开始的x)的质因子最多有一个,也就是剩下的x,这点也是刚想通,因为x已经无法被小于sqrt的质数分解了,所以剩下的x一定是质子;{int length=times.size();for(int j=0;j<length;j++)times.push_back(x*times[j]);                  }}
int main() {prime2();int n ; cin >> n;vector<pair<int, int> > arr(n), ans(n);for (int i = 0; i < n; i++) {scanf("%d",& arr[i].first);arr[i].second = i;}sort(arr.begin(), arr.end());for (int i = 0; i < n; i++) {if (i == 0 || arr[i-1].first != arr[i].first) {asd(arr[i].first);ans[arr[i].second] = make_pair(times[times.size()-1], arr[i].first/times[times.size()-1]);times.pop_back();} else {if(times.empty()){cout<<"NO"<<endl;return 0;}//说明p[i]的所有组合已经组完了,所以没法不重复的分解了ans[arr[i].second] =make_pair(times[times.size()-1], arr[i].first / times[times.size()-1]);times.pop_back(); }
}cout << "YES" << endl;for (int i = 0; i < n; i++) {printf("%d %d\n",ans[i].first ,ans[i].second );}return 0;
}在这里插入代码片

Gym - 101911D(转化为求因子)相关推荐

  1. 1104: 求因子和(函数专题)

    1104: 求因子和(函数专题) 时间限制: 1 Sec 内存限制: 128 MB 提交: 4633 解决: 3669 [提交] [状态] [讨论版] [命题人:admin] 题目描述 输入正整数n( ...

  2. ZZULIOJ 1104: 求因子和(函数专题)

    求因子和(函数专题) 题目描述 输入正整数n(2<=n<=1000),计算并输出n的所有正因子(包括1,不包括自身)之和.要求程序定义一个FacSum ()函数和一个main()函数,Fa ...

  3. C#语言平面坐标计算,平面坐标转化经纬度,求高手给C# 方法,将下列坐标转化成经纬度...

    平面坐标转化经纬度,求高手给C# 方法,将下列坐标转化成经纬度 平面坐标转化经纬度,求高手给C# 方法,将下列坐标转化成经纬度 53950.65966 98691.8174 53978.58712 9 ...

  4. java求因子_一个数恰好等于它的因子之和java

    下面的java基础编程题是如果一个数恰好等于它的因子之和的相关内容,一起来了解一下具体的题目和java的实现方式吧. 一.题目 一个数假如恰好等于它的因子之和,那么这个数就被叫做"完数&qu ...

  5. 等式(分解质因子求因子个数)

    链接: https://www.nowcoder.com/acm/contest/90/F 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言6553 ...

  6. python求因子代码_Python量化入门:饱受青睐的三因子模型「附代码及数据」

    代码及数据见文章最后. 主要内容: 一.CAPM的不足与三因子模型的诞生 二.三因子模型的原理 三.Python三因子模型选股实战 一.CAPM的不足与三因子模型的诞生 CAPM模型经历了大量的实证和 ...

  7. 7809 - 试题J:因数个数 25'(欧拉筛法求因子个数)

    链接:http://oj.hzjingma.com/p/7809?view=classic 来源:竞码编程 题目描述   求所有 2 2 2 到 n n n 的整数中,因数个数第 k k k 少的数因 ...

  8. 一道求因子之和面试算法题

    package com.project;/*一个数如果恰好等于它的因子之和,这个数就称为"完数".例如6=1+2+3.编程 找出1000以内的所有完数.(因子:除去这个数本身的其它 ...

  9. 分解因数和求因子个数

    1.分解因数 链接:分解因数__牛客网 来源:牛客网 所谓因子分解,就是把给定的正整数a,分解成若干个素数的乘积,即 a = a1 × a2 × a3 × ... × an,并且 1 < a1 ...

最新文章

  1. 又一个防火墙的问题——content filtering
  2. mysql学_MySQL学习(一)
  3. MyBatis多数据源配置(读写分离)
  4. Jenkins 创建一个freestyle的Job
  5. layui自定义查询条件html页面,Layui的数据表格+springmvc实现搜索功能的例子_飛雲_前端开发者...
  6. java的多态怎么理解_JAVA多态的理解
  7. Python--26 简单定制 计时器
  8. Java程序员从笨鸟到菜鸟之(四十八)细谈struts2(十)ognl概念和原理详解
  9. 程序员的发展方向是什么?
  10. Java中正则表达式、模式匹配与信息抽取
  11. 【Linux下载安装jdk8】
  12. 苹果cmsv10自适应高仿时光影院视频网站免费模板
  13. 寻仙服务器要维护多久,新寻仙正式服5.0.6.1更新公告
  14. 百度招聘Android客服端(2)
  15. python中将奇数和偶数分列
  16. Python|Leetcode《1044》|最长重复子串
  17. Win7开机提示任务管理器已停止工作解决方法
  18. vscode编译、调试stm32F4系列mcu的程序
  19. 启用php client,RabbitMQ(二):安装 和 PHP Client
  20. imacros中使用变量

热门文章

  1. mysql ibd 数据文件恢复极速恢复工具 ibd recover tool
  2. python基因差异分析_TCGA的差异基因分析
  3. 在外网通过ssh连接访问内网教程
  4. 2022-10-13 Android APP 全屏幕显示全透明沉浸式主题android:theme样式 Theme.TranslucentTheme
  5. 武林外传108句经典台词
  6. 领导又让我做可视化报告,找了几天,终于让我找到神器了
  7. C语言的一个程序是怎么执行的
  8. 【商城秒杀项目】-- 概况
  9. JAVASE项目之狼人杀
  10. 纳斯达克“乱打”中国牌 请林依轮敲闭市钟