【CF1154G】Minimum Possible LCM
2024-09-07 02:00:56
题意
给你 \(n\) 个数 \(a_i\) ,求出 \(\text{lcm}\) 最小的一对数。
\(n\le 10^6, a_i\le 10^7\)
题解
直接枚举 ,找到当前数最小的两个倍数,统计答案即可。
理论时间复杂度为 \(O(a_i\log a_i)\) ,实际运行效率要远高于此。
代码很好写。
#include<cstdio>
const int N=10000005;
int a[N],a2[N],aid[3],mx,n;
long long ans=1ll<<60;
inline int gi()
{
char c=getchar(); int x=0;
for(;c<'0'||c>'9';c=getchar());
for(;c>='0'&&c<='9';c=getchar())x=(x<<1)+(x<<3)+c-'0';
return x;
}
int main()
{
n=gi();
for(int i=1;i<=n;++i)
{
int x=gi();
a[x]?a2[x]=i:a[x]=i;
if(x>mx) mx=x;
}
for(int i=1;i<=mx;++i)
{
int v[3],id[3],tot=0;
for(int j=i;tot<2&&j<=mx;j+=i)
if(a[j])
{
v[++tot]=j,id[tot]=a[j];
if(a2[j]&&tot!=2) v[++tot]=j,id[tot]=a2[j];
}
if(tot==2&&ans>1ll*v[1]*v[2]/i)
{
ans=1ll*v[1]*v[2]/i;
aid[1]=id[1],aid[2]=id[2];
}
}
if(aid[1]>aid[2]) aid[1]^=aid[2]^=aid[1]^=aid[2];
printf("%d %d",aid[1],aid[2]);
}
最新文章
- jQuery 2.0.3 源码分析core - 整体架构
- MyBatis查询传一个参数时报错:There is no getter for property named &#39;sleevetype&#39; in &#39;class java.lang.Integer
- winrt 上的翻书特效组件 源码分享 转载请说明
- Java 动态写轮眼 SharinganJPanel (整理)
- meta viewport标签的使用说明(手机浏览缩放控制)
- JQUERY 选择
- iOS tabbar点击动画效果实现
- windows端口占用处理工具
- Android ViewPager实现图片标题轮播和点击事件
- 读论文系列:Object Detection ECCV2016 SSD
- PHP制作个人博客-广告位添加与调用 推荐文章数据调取
- IDEA安装ini4idea插件
- redis数据库可视化工具(RedisDesktopManager)
- Open-Source Cybersecurity Infrastructure
- 现代JavaScript函数库 usuallyjs 的安装和使用
- PHP APP端微信支付
- Java知多少(96)绘图之设置字型和颜色
- 关于 clock tree
- Tensorflow游乐场
- VC++中的__super::