题意

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

【CF1154G】Minimum Possible LCM的更多相关文章

  1. 【LeetCode】Minimum Depth of Binary Tree 二叉树的最小深度 java

    [LeetCode]Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum dept ...

  2. 【POJ2516】Minimum Cost

    [POJ2516]Minimum Cost 题意:有N个收购商.M个供应商.K种物品.对于每种物品,每个供应商的供应量和每个收购商的需求量已知.每个供应商与每个收购商之间运送该物品的运费已知.求满足收 ...

  3. 【51NOD-0】1012 最小公倍数LCM

    [算法]欧几里德算法 #include<cstdio> int gcd(int a,int b) {?a:gcd(b,a%b);} int main() { int a,b; scanf( ...

  4. 【Leetcode】【Easy】Minimum Depth of Binary Tree

    Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shor ...

  5. 【leetcode】Minimum Depth of Binary Tree

    题目简述: Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along th ...

  6. 【leetcode】Minimum Path Sum

    Minimum Path Sum Given a m x n grid filled with non-negative numbers, find a path from top left to b ...

  7. 【leetcode】Minimum Window Substring (hard) ★

    Given a string S and a string T, find the minimum window in S which will contain all the characters ...

  8. 【leetcode】Minimum Depth of Binary Tree (easy)

    Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shor ...

  9. 【hdu1394】Minimum Inversion Number

    Problem Description The inversion number of a given number sequence a1, a2, ..., an is the number of ...

随机推荐

  1. 吴裕雄 Bootstrap 前端框架开发——Bootstrap 表格:表示信息变化的操作

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  2. Zabbix在Docker中的应用和监控

    目录 Zabbix在Docker中的应用和监控 一.如何使Zabbix跑在Docker里 1.Docker基础环境配置 2.Docker-compose安装配置 3.启动zabbix server 4 ...

  3. java程序中的经常出现的的异常处理课后总结

    一.JDK中常见的异常情况 1.常见异常总结图 2.java中异常分类 Throwable类有两个直接子类: (1)Exception:出现的问题是可以被捕获的 (2)Error:系统错误,通常由JV ...

  4. 不一样的Vue实战3:布局与组件

    不一样的Vue实战3:布局与组件  发表于 2017-06-05 |  分类于 web前端|  |  阅读次数 11534 http://yangyi1024.com/2017/06/05/%E4%B ...

  5. node服务端口被占用

    今天在输入node .\app.js启动api接口时出现了以下报错: 出现这个报错说明端口被占用:Error: listen EADDRINUSE: address already in use :: ...

  6. 小米xiaomi9 google play卡在检查信息

    终于在今年淘汰掉用了三年的果6s,换了小米9 ,结果发现科学..上网后,可以正常打开google网页,却无法登陆,gmail也无法使用.一直卡在“正在核对信息”. 检查服务,小米9 全系列自带了谷歌框 ...

  7. Vue3中的Proxy作用在哪里?

    目录 前言 Vue没有Proxy会怎么样? proxy开始 前言 在讲解Proxy之前,我们有些前置知识点是必要掌握的: Object相关静态函数 Reflect相关静态函数 简单说明知识盲点 名称 ...

  8. P1093 字符串A+B

    1093 字符串A+B (20分)   给定两个字符串 A 和 B,本题要求你输出 A+B,即两个字符串的并集.要求先输出 A,再输出 B,但重复的字符必须被剔除. 输入格式: 输入在两行中分别给出  ...

  9. visio 2019 激活方法

    今日因工作需要使用visio,无奈下载2019版本需要激活,很多功能无法使用,最近在网上发现一个非常简单就是一个本地可执行脚本,本人已亲测完全激活成功,随分享给大家 复制下面代码: @echo off ...

  10. [前端] Vue封装播放器、打包、上传NPM

    一.使用icomoon 1.生成和下载图标相关文件 先使用icomoon获取我们要使用的图标,例如播放.暂停.停止.全屏等图标. icomoon网站:https://icomoon.io/app/#/ ...