Divisors of Two Integers CodeForces - 1108B (数学+思维)
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 xxand 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 xxand 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
10
10 2 8 1 2 4 1 20 4 5
20 8 题意:
给定一个数组,这个数组包含了两个正整数a和b的所有因子,包括1和a,b,如果x同为a和b的因子,那么数组中x出现两次。
让求出a和b的数值。
思路:首先对数组进行排序,那么最大值一定是我们a和b中的一个(原因自行思考)。那么我们最大值是a。
然后我们暴力的把a的所有因子都求出来,从数组中删除一次,然后剩下的数组中的最大值就是我们要找的b。
细节见代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define db(x) cout<<"== [ "<<x<<" ] =="<<endl;
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD){ll ans=;while(b){if(b%)ans=ans*a%MOD;a=a*a%MOD;b/=;}return ans;}
inline void getInt(int* p);
const int maxn=;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
ll n;
ll a[maxn];
int main()
{
gbtb;
cin>>n;
map<ll,ll> m;
repd(i,,n)
{
cin>>a[i];
m[a[i]]++;
}
sort(a+,a++n); ll x=1ll;
ll y=1ll;
y=a[n]; for(ll i=;i<=y;i++)
{
if(y%i==)
m[i]--;
}
for(ll i=;i>=;i--)
{
if(m[i]==)
{
x=i;
break;
}
}
cout<<x<<" "<<y;
return ;
} inline void getInt(int* p) {
char ch;
do {
ch = getchar();
} while (ch == ' ' || ch == '\n');
if (ch == '-') {
*p = -(getchar() - '');
while ((ch = getchar()) >= '' && ch <= '') {
*p = *p * - ch + '';
}
}
else {
*p = ch - '';
while ((ch = getchar()) >= '' && ch <= '') {
*p = *p * + ch - '';
}
}
}
Divisors of Two Integers CodeForces - 1108B (数学+思维)的更多相关文章
- B. Tell Your World(几何数学 + 思维)
B. Tell Your World time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- 程序设计中的数学思维函数总结(代码以C#为例)
最近以C#为例,学习了程序设计基础,其中涉及到一些数学思维,我们可以巧妙的将这些逻辑问题转换为代码,交给计算机运算. 现将经常会使用到的基础函数做一总结,供大家分享.自己备用. 1.判断一个数是否为奇 ...
- PJ考试可能会用到的数学思维题选讲-自学教程-自学笔记
PJ考试可能会用到的数学思维题选讲 by Pleiades_Antares 是学弟学妹的讲义--然后一部分题目是我弄的一部分来源于洛谷用户@ 普及组的一些数学思维题,所以可能有点菜咯别怪我 OI中的数 ...
- B. Divisors of Two Integers
B. Divisors of Two Integers time limit per test 1 second memory limit per test 256 megabytes input s ...
- UVa10025 The ? 1 ? 2 ? ... ? n = k problem 数学思维+规律
UVa10025 ? 1 ? 2 ? ... ? n = k problem The problem Given the following formula, one can set operator ...
- Codeforces Round #272 (Div. 2) C. Dreamoon and Sums (数学 思维)
题目链接 这个题取模的时候挺坑的!!! 题意:div(x , b) / mod(x , b) = k( 1 <= k <= a).求x的和 分析: 我们知道mod(x % b)的取值范围为 ...
- Codeforces Round #555 (Div. 3) D. N Problems During K Days 【数学思维】
一 题面 D. N Problems During K Days 二 分析 对于这题,刚开始我就是陷入了对公式的执着,企图用公式直接确定第一个数,然后试着去找序列.经过思考和手动模拟后发现是很难保证正 ...
- Sum of Consecutive Integers LightOJ - 1278(推公式 数学思维)
原文地址:https://blog.csdn.net/qq_37632935/article/details/79465213 给你一个数n(n<=10^14),然后问n能用几个连续的数表示; ...
- Minimum Integer CodeForces - 1101A (思维+公式)
You are given qq queries in the following form: Given three integers lili, riri and didi, find minim ...
随机推荐
- 孟岩:怎么看待Coin与Token的关系?
由于中英文的隔阂,很多在英文世界里一目了然.不言自明的词汇,翻译成中文之后意义模糊.难以理解.比如在区块链和加密数字货币领域,coin 和 token 的区别,很长时间困扰着我们,并且引发争论. 后来 ...
- c/c++ 智能指针 weak_ptr 使用
智能指针 weak_ptr 使用 weak_ptr用途: 1,解决空悬指针问题 2,解决循环引用问题 weak_ptr特点:没有*操作和->操作 weak_ptr是不控制所指对象生存周期的智能指 ...
- VSCode 首次打开提示“Git installation not found.”解决方案
※前提大家先在本地安装好相应的git版本(下载地址:https://www.git-scm.com/download/) 一.找到“默认用户设置”
- jQuery设置radio、select、checkbox只读属性后,如何在后台得到数据
1 设置表单的readonly属性 对于radio.select.checkbox来说,readonly属性对这三个标签不起什么作用. 2 设置表单的disabled属性 以radio为例说明. 代码 ...
- MySql基本使用方法
一,基本概念 1, 常用的两种引擎: (1) InnoDB a,支持ACID,简单地说就是支持事务完整性.一致性: b,支持行锁,以及类似ORACLE的一 ...
- php笔记(一)php介绍及数据类型
php 官方手册:http://php.net/manual/zh/ 1.PHP(全称 Hypertext Preprocessor,超文本预处理器的字母缩写)是一种服务器端脚本语言,它可嵌入到 HT ...
- 如何用Jupyter notebook打开本地数据集
首先打开本地Jupyter notebook,出现类似页面并进入网页端Home. 网页端界面类似如下: 需要注意的是,Jupyter notebook只能打开当前目录下的数据集,如csv,所以需要使用 ...
- 第八章 计时器(BEEPER1)
*------------------------------------- BEEPER1.C -- Timer Demo Program No. (c) Charles Petzold, ---- ...
- Nginx使用教程(七):使用Nginx缓存之proxy cache
定义缓存目录 <br\>使用您喜欢的文本编辑器打开/etc/nginx/nginx.conf,并在http {区域加入: proxy_cache_path /var/www/cache ...
- 寒假训练——搜索——C - Robot
The Robot Moving Institute is using a robot in their local store to transport different items. Of co ...