G. Minimum Possible LCM
https://codeforces.com/contest/1154/problem/G
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e7+1;
int a[N],pos[N][3];//pos【i】【j】表示数字i出现位置,j代表出现次数
int countt[N],ans1,ans2,p[N],C;
ll M=1e18;
inline int read(){
int sum=0;
int x=1;
char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-')
x=0;
ch=getchar();
}
while(ch>='0'&&ch<='9')
sum=(sum<<1)+(sum<<3)+(ch^48),ch=getchar();
return x?sum:-sum;
}
int main(){
ios::sync_with_stdio(false);
int n=read();
//cin>>n;
for(int i=1;i<=n;i++){
int x=read();
//cin>>x;
a[x]++;
if(countt[x]<2)
pos[x][++countt[x]]=i;//记录位置,只要出现俩次就行了
}
//暴力枚举存在因子
for(int i=1;i<N;i++){
//如果有俩因子:ans1=i*j,ans2=i*j(与前面j不一定相同)
for(int j=1;i*j<N;j++){
while(a[i*j]&&C<2)//出现的就拿来用,减去存在次数(-1)
a[i*j]--,p[++C]=j;
if(C==2)
break;
}
//更新最小值
if(C==2&&M>(ll )p[1]*p[2]*i)
M=(ll)p[1]*p[2]*i,ans1=i*p[1],ans2=i*p[2];
while(C)//生成新的数则存在次数+1
a[i*p[C--]]++;
}
//找位置 如果俩个相同,则要输出不同位置,
if(ans1==ans2)
ans1=pos[ans1][1],ans2=pos[ans2][2];
else
ans1=pos[ans1][1],ans2=pos[ans2][1];
if(ans1>ans2)
swap(ans1,ans2);
cout<<ans1<<" "<<ans2;
return 0;
}
G. Minimum Possible LCM的更多相关文章
- Codeforces Round #552:G. Minimum Possible LCM
官方题解是时间复杂度为O(nd)的.这里给出一个简单实现但是时间复杂度为O(NlogN) (N=1e7) 因为 a*b/gcd(a,b)=lcm(a,b) 所以我们可以枚举每一个因子,然后找到存在这个 ...
- Codeforces B. Minimum Possible LCM(贪心数论)
题目描述: B. Minimum Possible LCM time limit per test 4 seconds memory limit per test 1024 megabytes inp ...
- Minimum Sum LCM(uva10791+和最小的LCM+推理)
L - Minimum Sum LCM Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submi ...
- UVA.10791 Minimum Sum LCM (唯一分解定理)
UVA.10791 Minimum Sum LCM (唯一分解定理) 题意分析 也是利用唯一分解定理,但是要注意,分解的时候要循环(sqrt(num+1))次,并要对最后的num结果进行判断. 代码总 ...
- Codeforces 1154G Minimum Possible LCM
题目链接:http://codeforces.com/problemset/problem/1154/G 题目大意: 给定n个数,在这些数中选2个数,使这两个数的最小公倍数最小,输出这两个数的下标(如 ...
- 数论-质因数(gcd) UVa 10791 - Minimum Sum LCM
https://vjudge.net/problem/UVA-10791/origin 以上为题目来源Google翻译得到的题意: 一组整数的LCM(最小公倍数)定义为最小数,即 该集合的所有整数的倍 ...
- F - Minimum Sum LCM
LCM (Least Common Multiple) of a set of integers is defined as the minimum number, which is a multip ...
- G - GCD and LCM 杭电
Given two positive integers G and L, could you tell me how many solutions of (x, y, z) there are, sa ...
- UVA 10791 Minimum Sum LCM(分解质因数)
最大公倍数的最小和 题意: 给一个数字n,范围在[1,2^23-1],这个n是一系列数字的最小公倍数,这一系列数字的个数至少为2 那么找出一个序列,使他们的和最小. 分析: 一系列数字a1,a2,a3 ...
随机推荐
- InstrumentationTextCase 测试
<instrumentation android:name="android.test.InstrumentationTestRunner" an ...
- POJ 1125:Stockbroker Grapevine
Stockbroker Grapevine Time Limit: 1000MS Memory Limit: 10000KB 64bit IO Format: %I64d & %I64 ...
- 腾讯大佬告诉你,写Python到底用什么IDE合适
不管你是 Python 新手还是老鸟,肯定纠结过一个问题: 到底用什么编辑器写 Python 代码好? 为此,我们调查了数十位鹅厂程序猿们爱用的 Python IDE,从他们对每款编辑器的看法中,也许 ...
- Mac OS/Windows好用软件分享
下软件全部为破解版,仅供参考学习用,如涉及商业. 请支持正版!谢谢 全部为本人亲测过 看上哪个留言发给你! 直接全分享上来会有人居心不良!
- blueimp,预览遮罩范围控制
blueimg gallery github地址:https://github.com/blueimp/Gallery/blob/master/README.md 使用前提,引用css和js < ...
- Centos7下yum安装软件报错解决办法
Traceback (most recent call last): File "/usr/bin/yum", line 29, in yummain.user_main(sys. ...
- PAT-树-DFS-BFS相关问题解决方案整理
如何建树? 二叉树-建树-方式一 dfs使用root左右指针建立树节点关系,返回根节点root 二叉树-建树-方式二 dfs使用二维数组,int nds[n][2],如:nds[i][0]表示i节点的 ...
- 安装lombok插件IDEA的插件栏加载不出来
打开 Setting-->Appearance & Behavior -->Syetem Setting -->Updates,将Use secure connection ...
- c++静态库和动态库的添加
# 声明要求的 cmake 最低版本cmake_minimum_required(VERSION 2.8)# 声明一个 cmake 工程project(helloSLAM) # 设置编译模式set( ...
- WinServer--mstsc
部署项目时,远程连接服务器一直提示连接达最大拒绝连接. mstsc /admin 从sp2后,/console参数就改为/admin了,其实就是登陆到远程服务器的控制台,一般加这个参数是为了在远程桌面 ...