Codeforces-B-Divisors of Two Integers(思维技巧)
Recently you have received two positive integer numbers xx and yy. You forgot them, but you remembered a shuffled list containing all divisors of xx (including 11 and xx) and all divisors of yy (including 11 and yy). If dd is a divisor of both numbers xx and yy at the same time, there are two occurrences of dd in the list.
For example, if x=4x=4 and y=6y=6 then the given list can be any permutation of the list [1,2,4,1,2,3,6][1,2,4,1,2,3,6]. Some of the possible lists are: [1,1,2,4,6,3,2][1,1,2,4,6,3,2], [4,6,1,1,2,3,2][4,6,1,1,2,3,2] or [1,6,3,2,4,1,2][1,6,3,2,4,1,2].
Your problem is to restore suitable positive integer numbers xx and yy that would yield the same list of divisors (possibly in different order).
It is guaranteed that the answer exists, i.e. the given list of divisors corresponds to some positive integers xx and yy.
Input
The first line contains one integer nn (2≤n≤1282≤n≤128) — the number of divisors of xx and yy.
The second line of the input contains nn integers d1,d2,…,dnd1,d2,…,dn (1≤di≤1041≤di≤104), where didi is either divisor of xx or divisor of yy. If a number is divisor of both numbers xx and yy then there are two copies of this number in the list.
Output
Print two positive integer numbers xx and yy — such numbers that merged list of their divisors is the permutation of the given list of integers. It is guaranteed that the answer exists.
Example
input
Copy
10
10 2 8 1 2 4 1 20 4 5
output
Copy
20 8
思路:先选出最大的,然后去遍历是他取模为0的并标记一下,其余的存在另一个数组里,在筛选出最大的
代码:
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int a[150];
int b[150];
int vis[10005];
int main()
{
int n;
cin>>n;
for(int t=0;t<n;t++)
{
scanf("%d",&a[t]);
}
sort(a,a+n);
int l=a[n-1];
int s=0;
for(int t=0;t<n;t++)
{
if(l%a[t]==0&&vis[a[t]]==0)
{
vis[a[t]]=1;
continue;
}
else
{
b[s++]=a[t];
}
}
sort(b,b+s);
cout<<l<<" "<<b[s-1]<<endl;
return 0;
}
Codeforces-B-Divisors of Two Integers(思维技巧)的更多相关文章
- 更快学习 JavaScript 的 6 个思维技巧
更快学习 JavaScript 的 6 个思维技巧 我们在学习JavaScript,或其他任何编码技能的时候,往往是因为这些拦路虎而裹足不前: 有些概念可能会造成混淆,尤其当你是从其他语言转过来的时候 ...
- B. Divisors of Two Integers
B. Divisors of Two Integers time limit per test 1 second memory limit per test 256 megabytes input s ...
- Divisors of Two Integers CodeForces - 1108B (数学+思维)
Recently you have received two positive integer numbers xx and yy. You forgot them, but you remember ...
- CF思维联系–CodeForces - 222 C Reducing Fractions(数学+有技巧的枚举)
ACM思维题训练集合 To confuse the opponents, the Galactic Empire represents fractions in an unusual format. ...
- Educational Codeforces Round 33 (Rated for Div. 2) B. Beautiful Divisors【进制思维/打表】
B. Beautiful Divisors time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- Codeforces Round #143 (Div. 2) (ABCD 思维场)
题目连链接:http://codeforces.com/contest/231 A. Team time limit per test:2 seconds memory limit per test: ...
- Codeforces Round #395 (Div. 2)(A.思维,B,水)
A. Taymyr is calling you time limit per test:1 second memory limit per test:256 megabytes input:stan ...
- Codeforces Round #416 (Div. 2)(A,思维题,暴力,B,思维题,暴力)
A. Vladik and Courtesy time limit per test:2 seconds memory limit per test:256 megabytes input:stand ...
- Codeforces Round #542(Div. 2) CDE 思维场
C https://codeforces.com/contest/1130/problem/C 题意 给你一个\(n*m\)(n,m<=50)的矩阵,每个格子代表海或者陆地,给出在陆地上的起点终 ...
随机推荐
- js分页demo
纯js实现分页 原理:所有数据已加载好,js通过遍历部分显示,实现分页效果 html代码 <html> <head> <meta charset='utf-8'> ...
- Android中同一个ImageView中根据状态显示不同图片
一般: if(条件1) { image.setBackground(R.id.xxx1); } else if (条件2) { image.setBackground(R.id.xxx2); } 实际 ...
- codeforces 1064D 双端队列BFS
双端队列BFS解决的就是路径权值可能为0的图最短路问题,权值为0插入队头,否则插入队尾. 对于这个题,可以看作上下移动的路径的权值为0,左右移动权值为1,而且不能超过规定的步数. 直接广搜求覆盖的点的 ...
- jquery checkbox (选中和取消选中事件on("change"))做笔记
$("#btn_Company").attr("disabled", "disabled"); $("#agency") ...
- python---pyspider,报错?
conf.json文件内容如下: { "message_queue": "redis://127.0.0.1:6379/15", "webui&quo ...
- 删除GHOST中win7桌面IE删不掉的解决办法
打开Win+R 运行regedit 依次打开: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Deskto ...
- Jsp入门第一天
1. JSP: 1). WHY: JSP 是简 Servlet 编写的一种技术, 它将 Java 代码和 HTML 语句混合在同一个文件中编写,只对网页中的要动态产生的内容采用 Java 代码来编写, ...
- Gremlin:图遍历语言
Gremlin简介 Gremlin是Apache TinkerPop 框架下的图遍历语言.Gremlin是一种函数式数据流语言,可以使得用户使用简洁的方式表述复杂的属性图(property graph ...
- DNS线路
文章介绍 填写DNS地址时候,比较好记的就114.114.114.114,8.8.8.8,9.9.9.9,几个,但是常用的有哪些呢?这篇文章就简单介绍下了. 前言 两年多前,曾发帖对国内主流公共 DN ...
- [Emacs] Org-mode下表格内中英文不对齐的解决方案
;; Setting for English font (set-default-font "monospace-15") ;; Setting for Chinese font ...