题意

给你 \(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]);
}

最新文章

  1. jQuery 2.0.3 源码分析core - 整体架构
  2. MyBatis查询传一个参数时报错:There is no getter for property named &#39;sleevetype&#39; in &#39;class java.lang.Integer
  3. winrt 上的翻书特效组件 源码分享 转载请说明
  4. Java 动态写轮眼 SharinganJPanel (整理)
  5. meta viewport标签的使用说明(手机浏览缩放控制)
  6. JQUERY 选择
  7. iOS tabbar点击动画效果实现
  8. windows端口占用处理工具
  9. Android ViewPager实现图片标题轮播和点击事件
  10. 读论文系列:Object Detection ECCV2016 SSD
  11. PHP制作个人博客-广告位添加与调用 推荐文章数据调取
  12. IDEA安装ini4idea插件
  13. redis数据库可视化工具(RedisDesktopManager)
  14. Open-Source Cybersecurity Infrastructure
  15. 现代JavaScript函数库 usuallyjs 的安装和使用
  16. PHP APP端微信支付
  17. Java知多少(96)绘图之设置字型和颜色
  18. 关于 clock tree
  19. Tensorflow游乐场
  20. VC++中的__super::

热门文章

  1. scrollView嵌套
  2. 十四 Spring的AOP的基于AspectJ的注解开发
  3. Vue中img标签src属性绑定
  4. Vue 路由组件
  5. bootloader 详细介绍
  6. 在linux中安装redis
  7. Day4-B-最短路径问题 HDU3790
  8. RCast 66: 射影几何与Rho演算
  9. WCF 学习
  10. 牛客小白月赛3---G 旅游(树形dp)