https://codeforces.com/contest/1154/problem/G

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e7+1;
int a[N],pos[N][3];//pos【i】【j】表示数字i出现位置,j代表出现次数
int countt[N],ans1,ans2,p[N],C;
ll M=1e18;
inline int read(){
int sum=0;
int x=1;
char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-')
x=0;
ch=getchar();
}
while(ch>='0'&&ch<='9')
sum=(sum<<1)+(sum<<3)+(ch^48),ch=getchar();
return x?sum:-sum;
}
int main(){
ios::sync_with_stdio(false);
int n=read();
//cin>>n;
for(int i=1;i<=n;i++){
int x=read();
//cin>>x;
a[x]++;
if(countt[x]<2)
pos[x][++countt[x]]=i;//记录位置,只要出现俩次就行了
}
//暴力枚举存在因子
for(int i=1;i<N;i++){
//如果有俩因子:ans1=i*j,ans2=i*j(与前面j不一定相同)
for(int j=1;i*j<N;j++){
while(a[i*j]&&C<2)//出现的就拿来用,减去存在次数(-1)
a[i*j]--,p[++C]=j;
if(C==2)
break;
}
//更新最小值
if(C==2&&M>(ll )p[1]*p[2]*i)
M=(ll)p[1]*p[2]*i,ans1=i*p[1],ans2=i*p[2];
while(C)//生成新的数则存在次数+1
a[i*p[C--]]++;
}
//找位置 如果俩个相同,则要输出不同位置,
if(ans1==ans2)
ans1=pos[ans1][1],ans2=pos[ans2][2];
else
ans1=pos[ans1][1],ans2=pos[ans2][1];
if(ans1>ans2)
swap(ans1,ans2);
cout<<ans1<<" "<<ans2;
return 0;
}

  

G. Minimum Possible LCM的更多相关文章

  1. Codeforces Round #552:G. Minimum Possible LCM

    官方题解是时间复杂度为O(nd)的.这里给出一个简单实现但是时间复杂度为O(NlogN) (N=1e7) 因为 a*b/gcd(a,b)=lcm(a,b) 所以我们可以枚举每一个因子,然后找到存在这个 ...

  2. Codeforces B. Minimum Possible LCM(贪心数论)

    题目描述: B. Minimum Possible LCM time limit per test 4 seconds memory limit per test 1024 megabytes inp ...

  3. Minimum Sum LCM(uva10791+和最小的LCM+推理)

    L - Minimum Sum LCM Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submi ...

  4. UVA.10791 Minimum Sum LCM (唯一分解定理)

    UVA.10791 Minimum Sum LCM (唯一分解定理) 题意分析 也是利用唯一分解定理,但是要注意,分解的时候要循环(sqrt(num+1))次,并要对最后的num结果进行判断. 代码总 ...

  5. Codeforces 1154G Minimum Possible LCM

    题目链接:http://codeforces.com/problemset/problem/1154/G 题目大意: 给定n个数,在这些数中选2个数,使这两个数的最小公倍数最小,输出这两个数的下标(如 ...

  6. 数论-质因数(gcd) UVa 10791 - Minimum Sum LCM

    https://vjudge.net/problem/UVA-10791/origin 以上为题目来源Google翻译得到的题意: 一组整数的LCM(最小公倍数)定义为最小数,即 该集合的所有整数的倍 ...

  7. F - Minimum Sum LCM

    LCM (Least Common Multiple) of a set of integers is defined as the minimum number, which is a multip ...

  8. G - GCD and LCM 杭电

    Given two positive integers G and L, could you tell me how many solutions of (x, y, z) there are, sa ...

  9. UVA 10791 Minimum Sum LCM(分解质因数)

    最大公倍数的最小和 题意: 给一个数字n,范围在[1,2^23-1],这个n是一系列数字的最小公倍数,这一系列数字的个数至少为2 那么找出一个序列,使他们的和最小. 分析: 一系列数字a1,a2,a3 ...

随机推荐

  1. Hibernate--(二)增删改查

    1.增删改查: public class Test { public static void main(String[] args) { SessionFactory sf = new Configu ...

  2. 从架构师视角看是否该用Kotlin做服务端开发?

    前言 自从Oracle收购Sun之后,对Java收费或加强控制的尝试从未间断,谷歌与Oracle围绕Java API的官司也跌宕起伏.虽然Oracle只是针对Oracle JDK8的升级收费,并释放了 ...

  3. 吴裕雄--天生自然 JAVASCRIPT开发学习:事件

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

  4. decltype关键字

    decltype用于编译时类型推导,是以一个普通表达式作为参数,返回该表达式的类型,而且decltype并不会对表达式进行求值. decltype的用法: //推导出表达式类型 ; decltype( ...

  5. C++ 一个exe的两个运行实例之间共享数据

    #pragma data_seg("Shared") volatile int iNum = 0; #pragma data_seg() #pragma comment(linke ...

  6. Redis的学习之路

    应用场景 1.作为缓存使用  (1)原始业务功能设计 秒杀 双十一.618 排队购票 (2)运营平台察觉到突发式高频访问热点 突发式热点新闻 (3)高频复杂的统计数据 在线直播 投票排行榜 2.附加功 ...

  7. 给vector对象添加元素的方法

    #include<iostream> #include<vector> using namespace std; int main() { //初始化10个元素,每个值都为0 ...

  8. css 的基础样式--border--padding--margin

    border 边框复合写法 border:border-width border-style border-color; border-width 边框宽度 border-style 边框样式:sol ...

  9. CentOS 7.3 安装redis 4.0.2服务

    CentOS 7.3 安装redis 4.0.2服务 1.下载解压 下载地址:/home/xiaoming/ wget http://download.redis.io/releases/redis- ...

  10. 康冕峰IT技术总结博客CSDN索引

    计算1-x内的质数, 结果保存在mysql中. Java 程序员面试笔试宝典 4.1基础知识https://blog.csdn.net/qq_40993412/article/details/1040 ...