题意

给你 \(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. MySQL帮助文档的使用

    帮助文档使用 在 MySQL 使用过程中,可能经常会遇到以下问题: 某个操作语法忘记了,需要快速查找. 当前版本上,某个字段类型我们想快速知道它的取值范围? 当前版本上,都支持哪些函数?希望有例子能快 ...

  2. 《React后台管理系统实战 :二》antd左导航:cmd批量创建子/目录、用antd进行页面布局、分离左导航为单独组件、子路由、动态写左导航、css样式相对陷阱

    一.admin页面布局及路由创建 0)cmd批量创建目录及子目录 //创建各个目录,及charts和子目录bar md home category product role user charts\b ...

  3. 暴强贴:从.NET平台调用Win32 API----转载

      水之真谛 关注 17人评论 27649人阅读 2007-02-28 17:03:47 作者:刘铁猛日期:2005-12-20关键字:C# .NET Win32 API 版权声明:本文章受知识产权法 ...

  4. 初识IntPtr------转载

    初识IntPtr 一:什么是IntPtr 先来看看MSDN上说的:用于表示指针或句柄的平台特定类型.这个其实说出了这样两个事实,IntPtr 可以用来表示指针或句柄.它是一个平台特定类型.对于它的解释 ...

  5. 信号强度(RSSI)知识整理

    来源: https://www.cnblogs.com/lele/articles/2832885.html 为什么无线信号(RSSI)是负值 答:其实归根到底为什么接收的无线信号是负值,这样子是不是 ...

  6. xcode 6 如何将 模拟器(simulator) for iphone/ipad 转变成 simulator for iphone

    xcode 6默认模拟器是iphone/ipad通用的,如果想只针对iphone或者ipad可以进行如下设置: 1.修改模拟器大小(非必须) 模拟器->WIndow->scale-> ...

  7. 前端学习笔记系列一:9 js中数组的拷贝

    拷贝分为浅拷贝和深拷贝,在JavaScript中能够实现这两种拷贝的方式也是多种多样.以下是一维数组实现深拷贝和浅拷贝的各种方式. 一.浅拷贝 1.赋值 赋值是最直接的一种浅拷贝. let arr3 ...

  8. 图的Prim,Kruskal,Dijkstra,Floyd算法

    代码部分有点问题,具体算法没问题, 最近期末考,要过段时间才会修改 //邻接矩阵,具体情况看上一篇的图的实现template<class T>class MGraph {public:   ...

  9. Opencv中常见的滤波方法

    滤波(模糊)的概念和作用: 图像滤波增强处理实质上就是运用滤波技术来增强图像的某些空间频率特征,以改善地物目标与领域或背景之间的灰度反差. 遥感系统成像过程中可能产生的”模糊”作用,常使遥感图像上某些 ...

  10. 嵊州普及Day5T1

    题意:有n个商店,自家商店的定价不可高于任何一家商店定价,求自家商店最高定价. 思路:拿个变量打擂台即可,不用解释太多. 见代码: #include<iostream> #include& ...