B. Divisors of Two Integers
1 second
256 megabytes
standard input
standard output
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.
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.
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.
10
10 2 8 1 2 4 1 20 4 5
20 8
#include<iostream>
#include<algorithm>
using namespace std;
#define ll long long
int a[],b[];
int main()
{
int n,j=;
cin>>n;
for(int i=;i<n;i++)
{
cin>>a[i];
}
sort(a,a+n);
cout<<a[n-]<<" ";
for(int i=;i<=a[n-];i++)
{
if(a[n-]%i==)
{
b[j]=i;
j++;
}
}
for(int k=;k<j;k++)
{
for(int i=;i<n;i++)
{
if(a[i]==b[k])
{
a[i]=;
break;
}
}
}
sort(a,a+n);
cout<<a[n-]<<endl; return ; }
B. Divisors of Two Integers的更多相关文章
- Divisors of Two Integers CodeForces - 1108B (数学+思维)
Recently you have received two positive integer numbers xx and yy. You forgot them, but you remember ...
- codeforce --- 237C
C. Primes on Interval time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- Primes on Interval(二分 + 素数打表)
Primes on Interval Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u ...
- Codeforces 237C
题目: Description You've decided to carry out a survey in the theory of prime numbers. Let us remind y ...
- Codeforces Round #535 (Div. 3) 解题报告
CF1108A. Two distinct points 做法:模拟 如果两者左端点重合就第二条的左端点++就好,然后输出左端点 #include <bits/stdc++.h> usin ...
- Codeforces Round #535 (Div. 3) 题解
Codeforces Round #535 (Div. 3) 题目总链接:https://codeforces.com/contest/1108 太懒了啊~好久之前的我现在才更新,赶紧补上吧,不能漏掉 ...
- Codeforces Round #535 (Div. 3) [codeforces div3 难度测评]
hhhh感觉我真的太久没有接触过OI了 大约是前天听到JK他们约着一起刷codeforces,假期里觉得有些颓废的我忽然也心血来潮来看看题目 今天看codeforces才知道居然有div3了,感觉应该 ...
- Codeforces Round #535(div 3) 简要题解
Problem A. Two distinct points [题解] 显然 , 当l1不等于r2时 , (l1 , r2)是一组解 否则 , (l1 , l2)是一组合法的解 时间复杂度 : O(1 ...
- 【Codeforces1139D_CF1139D】Steps to One (Mobius_DP)
Problem: Codeforces 1139D Analysis: After ACing E, I gave up D and spent the left 30 minutes chattin ...
随机推荐
- Browsersync 简介 and 使用
简介 省时的浏览器同步测试工具,Browsersync能让浏览器实时.快速响应您的文件更改(html.js.css.sass.less等)并自动刷新页面. 曾经我们每改一次的代码,都需要手动去刷新一次 ...
- plsql中的执行体
在plsql中的sql windows窗口中,可以编写一段执行体来达到一定的目的,类似于写一段程序,可有逻辑判断. 大概的格式为 declare ----定义变量 begin ----- 执行体: e ...
- ios7适配--隐藏status bar
//viewDidload if ([self respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]) { // iOS 7 ...
- ParameterizedType的作用
public interface ParameterizedType extends Type subParam.Java package com.example.test; public clas ...
- HackThirteen 在onCreate()方法中获取View的宽度和高度
1.概要: Android源代码中很多模块都使用了post()方法,深入理解框架曾运行机制对于避开类似于本例中的小陷阱是很重要的 2.问题提出: 如果开发一些依赖于UI控件的宽和高的功 ...
- 一套最全的JavaScript 语言基础知识点总结(思维导图10张)
1.DOM基础操作 2.数组基础 3.函数基础 4.运算符 5.流程控制语句 6.正则表达式 7.字符串函数 8.数据类型 9.变量 10.window对象
- 以太坊系列之四: 使用atomic来避免lock
使用atomic来避免lock 在程序中为了互斥,难免要用锁,有些时候可以通过使用atomic来避免锁, 从而更高效. 下面给出一个以太坊中的例子,就是MsgPipeRW,从名字Pipe可以看出, 他 ...
- 死磕Java之聊聊LinkedList源码(基于JDK1.8)
工作快一年了,近期打算研究一下JDK的源码,也就因此有了死磕java系列 LinkedList 是一个继承于AbstractSequentialList的双向链表,链表不需要capacity的设定,它 ...
- ubuntu没有权限(不能)创建文件夹(目录)
可以在终端直接运行 sudo nautilus,弹出来的nautilus可以直接GUI操作,中途别关终端.如果遇到需要输入root密码,则输入root密码就可以启动这个图形界面了.
- 原码、反码、补码及位操作符,C语言位操作
计算机中的所有数据均是以二进制形式存储和处理的.所谓位操作就是直接把计算机中的二进制数进行操作,无须进行数据形式的转换,故处理速度较快. 1.原码.反码和补码 位(bit) 是计算机中处理数据的最小单 ...