题意

给你 \(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. 三 Spring对于延迟加载问题的解决

    Spring提供了延迟加载问题的解决方法 什么是延迟加载? 延迟加载:lazy(懒加载) 执行到该行代码的时候不会发送语句,真正使用这个对象的属性的时候才会发送sql语句进行查询. 类级别延迟加载:指 ...

  2. URL构成及各个协议默认端口

    url的构成:一般来说,http请求都会和URL地址有关,对于url来说一般由下面5个部分构成 .协议:通常就是第一个冒号之前的内容常见协议:http,https(http+ssl),ftp,ssh, ...

  3. 简述javascript的解析与执行

    我们知道浏览器中javascript程序的执行是基于变量与函数的.那么浏览器是如何保存数据,又是如何执行的呢?今天我们一起来探究一下! 0.写在前 最新的 ECMAScript 标准定义了 8 种数据 ...

  4. emWin 模拟器环境搭建

    转载http://www.nxpic.org/module/forum/thread-609329-1-1.html 这个模拟器工程在Segger官网下载:https://www.segger.com ...

  5. mysql分区介绍

    http://www.cnblogs.com/chenmh/p/5644713.html 介绍 可以针对分区表的每个分区指定各自的存储路径,对于innodb存储引擎的表只能指定数据路径,因为数据和索引 ...

  6. 一 Mybatis概述&与Hibernate的区别&CRUD

    Mybatis是类似Hibernate的ORM持久层框架 为什么学习Mybatis? 是目前国内主流的持久层框架,面向sql(相较于Hibernate,Mybatis一定要用sql) Hibernat ...

  7. CSS -- 盒子模型 margin 的特点

    margin在使用过程中具有如下的两个特点: 1.垂直外边距塌陷 --给子元素设置margin-top的时候,如果父元素也随着margin-top改变位置 解决方式: 给父元素设置边框 给父元素设置o ...

  8. Linux系统-----包管理器的演变

    每个电脑设备都使用某种形式的软件来执行其预定任务.在软件开发的早期,对产品进行了严格的bug和其他缺陷测试.在过去的十多年里,软件通过互联网发布,目的是通过应用新版本的软件来修复任何错误.在某些情况下 ...

  9. window 命令行telnet 不能用问题

    如图 解决办法 打开window控制面板,启用或关闭window功能,勾选telnet选项.

  10. Day5-T4

    原题目 Describe:最小生成树加权 code: #include<bits/stdc++.h> #define INF 214748364 #define eps 1e-9 #def ...