Minimum Possible LCM
https://codeforces.com/contest/1154/problem/G
题意:给定数组,求其中lcm(a,b)的最小的a和b的位置。
题解:枚举GCD
/*
*@Author: STZG
*@Language: C++
*/
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
//#define DEBUG
#define RI register int
#define endl "\n"
using namespace std;
typedef long long ll;
//typedef __int128 lll;
const int N=10000000+10;
const int M=100000+10;
const int MOD=1e9+7;
const double PI = acos(-1.0);
const double EXP = 1E-8;
const int INF = 0x3f3f3f3f;
int t,n,m,k,p,l,r,u,v;
ll ans[2],cnt,flag,temp,sum;
int vis[N];
char str;
int main()
{
#ifdef DEBUGfreopen("input.in", "r", stdin);//freopen("output.out", "w", stdout);
#endif//ios::sync_with_stdio(false);//cin.tie(0);//cout.tie(0);//scanf("%d",&t);//while(t--){scanf("%d",&n);ll maxl=1e18;for(int i=1;i<=n;i++){scanf("%d",&m);if(vis[m]){ll tempmax=m;if(tempmax<maxl){maxl=tempmax;ans[0]=vis[m];ans[1]=i;}}vis[m]=i;}for(int i=1;i<N;i++){sum=0;temp=0;for(int j=i;j<N;j+=i){if(vis[j])sum++;elsecontinue;if(sum&&!temp)temp=j;if(sum>=2){ll tempmax=temp/i*j;//cout<<temp<<j<<endl;if(tempmax<maxl){maxl=tempmax;ans[0]=vis[temp];ans[1]=vis[j];}break;}}}if(ans[0]>ans[1])swap(ans[0],ans[1]);cout<<ans[0]<<" "<<ans[1]<<endl;//}#ifdef DEBUGprintf("Time cost : %lf s\n",(double)clock()/CLOCKS_PER_SEC);
#endif//cout << "Hello world!" << endl;return 0;
}
Minimum Possible LCM相关推荐
- Minimum Sum LCM(uva10791+和最小的LCM+推理)
L - Minimum Sum LCM Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submi ...
- 28行代码AC——Minimum Sum LCM UVA - 10791(最大质因子)
励志用尽量少的代码做高效表达 题目(提交)链接-->UVA - 10791 题意 输入正整数n,找至少两个数,使得他们的最小公倍数(Least Common Multiple)为n且要输出最小的 ...
- UVA10791 Minimum Sum LCM(数论)
<span style="font-family:FangSong_GB2312;font-size:18px;">/* Sample Input 12 10 5 0 ...
- UVa 10791 Minimum Sum LCM
分析一波发现,将原数尽可能地分解成"质数的k次方"的和,会使得答案最大而数字和最小 于是就可以愉快地质因数分解了. 注意判断若n是质数,答案为n+1. 1 /**/ 2 #incl ...
- cf552 G Minimum Possible LCMn个数,求最小得一对lcm
You are given an array a consisting of n integers a1,a2,-,an Your problem is to find such pair of in ...
- 训练指南第二章-基础问题
训练指南第二章-基础问题 P170 2 / 4 Problem A UVA 10943 How do you add? 1 / 2 Problem B UVA 10780 Again Prime? N ...
- 《算法入门经典大赛——培训指南》第二章考试
UVa特别考试 UVa站点专门为本书设立的分类题库配合,方便读者提交: http://uva.onlinejudge.org/index.php?option=com_onlinejudge& ...
- 训练指南——数学专题一的总结
差不多一个星期过去了,在这一个多星期里,我做了一个数学专题和两场训练赛,要说对自己的感觉,只能说很差劲,开始的时候以为环境会比现在宽松很多,后来才发现想法是错误的,实验室室里室一种紧张的气氛,感觉就像 ...
- AOAPC I: Beginning Algorithm Contests 题解
AOAPC I: Beginning Algorithm Contests 题解 AOAPC I: Beginning Algorithm Contests (Rujia Liu) - Virtual ...
最新文章
- [Luogu] 聪聪可可
- MyEclipse 9.0 正式版公布新闻 下载
- C++ Primer 5th笔记(chap 18 大型程序工具) 多重继承与虚继承
- 一个高成熟度组织的规程和指南目录
- ZYNQ UARTLite接收不定长数据
- 属性,类方法,静态方法,反射
- 把CS文件编译成dll文件
- Acrobat Pro DC 教程,如何将纸质文档转换为可搜索的 PDF 文件?
- 【一周头条盘点】中国软件网(2018.7.2~2018.7.6)
- Kali安装中文输入法
- 如何解决DMS的个人数据隐私问题?ToF技术路线在路上
- 信息学奥赛一本通 1947:【09NOIP普及组】细胞分裂 | 洛谷 P1069 [NOIP2009 普及组] 细胞分裂
- 数据赋能,助力新零售数字化突围
- MySQL的数据类型(一)
- 计算机专业的硕士犯罪,计算机犯罪研究
- 字符中搜索字符或者字符串
- 基于win10 和python3.6激活虚拟环境成功!
- Herm Chart
- c语言米粒数实验报告,数字图像处理实验报告米粒
- Flyweight模式——读书笔记
热门文章
- cad批量偏移_学会这12个CAD制图命令,走遍天下都不怕,有没有兴趣?
- zookeeper版本更新_ZooKeeper入门,看这篇就够了!
- 华为服务器忘记管理密码怎么修改,忘记云服务器密码怎么修改
- gcc 删除elf_ELF文件格式解析器 原理 + 代码
- linuxpython重定向_linux命令重定向、、 1、 2、 1、 2、
- kcbzps oracle_快速进行Oracle安装及配置
- c语言编程算法模板,C语言编程算法精选.doc
- python高斯分布训练_Python画图高斯分布的示例
- 八、Flume的构架,安装和基本使用
- 三十六、Java集合中的HashMap