我预处理\(1e7log(1e7)\)的因数被T掉了,就不敢往这个复杂度想了……无奈去看AC代码

结果怎么暴举gcd剪一剪小枝就接近3s卡过去了!vector有锅(确信

const int maxn = 1e6 + 5, maxa = 1e7 + 5;
int n, a, l, r;
ll lcm = INF;
int f[maxa], s[maxa]; int main() {
read(n);
rep(i, 1, n) {
read(a);
if (f[a]) s[a] = i;
else f[a] = i;
}
rep(d, 1, maxa - 5) {
vector<pii> v;
for (int j = 1; j * d <= maxa - 5; j++) {
if (v.size() >= 2) break;
if (f[j * d]) v.push_back({j * d, f[j * d]});
if (s[j * d]) v.push_back({j * d, s[j * d]});
}
if (v.size() < 2) continue;
ll tmp = (ll)v[0].first / d * v[1].first;
if (lcm > tmp) {
lcm = tmp;
l = v[0].second;
r = v[1].second;
}
}
if (l > r) swap(l, r);
printf("%d %d\n", l, r);
return 0;
}

Codeforces 1154G(枚举)的更多相关文章

  1. Codeforces 1154G 枚举

    题意:给你一堆数,问其中lcm最小的一对数是什么? 思路:因为lcm(a, b) = a * b / gcd(a, b), 所以我们可以考虑暴力枚举gcd, 然后只找最小的a和b,去更新答案即可. 数 ...

  2. Codeforces 1154G Minimum Possible LCM

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

  3. codeforces 873E(枚举+rmq)

    题意 有n(n<=3000)个人参与acm比赛,每个人都有一个解题数,现在要决定拿金牌的人数cnt1,拿银牌的人数cnt2,拿铜牌的人数cnt3,各自对应一个解题数区间[d1,c1],[d2,c ...

  4. C. Vasily the Bear and Sequence Codeforces 336C(枚举,思维)

    C. Vasily the Bear and Sequence time limit per test 1 second memory limit per test 256 megabytes inp ...

  5. Codeforces 1216E2 枚举位数+二分

    两个二分 枚举位数 #include <bits/stdc++.h> #define MOD 1000000007 using namespace std; typedef long lo ...

  6. CodeForces - 748E (枚举+脑洞)

    E. Santa Claus and Tangerines time limit per test 2 seconds memory limit per test 256 megabytes inpu ...

  7. Codeforces 965 枚举轮数贪心分糖果 青蛙跳石头最大流=最小割思想 trie启发式合并

    A /*#include<cstring>#include<algorithm>#include<queue>#include<vector>#incl ...

  8. 数论(lcm)

    CodeForces - 1154G You are given an array a consisting of n integers a1,a2,…,an . Your problem is to ...

  9. Codeforces Round #103 (Div. 2) D. Missile Silos(spfa + 枚举边)

    题目链接:http://codeforces.com/problemset/problem/144/D 思路:首先spfa求出中心点S到其余每个顶点的距离,统计各顶点到中心点的距离为L的点,然后就是要 ...

随机推荐

  1. BZOJ 1626 [Usaco2007 Dec]Building Roads 修建道路:kruskal(最小生成树)

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1626 题意: 有n个农场,坐标为(x[i],y[i]). 有m条原先就修好的路,连接农场( ...

  2. JS遍历ChexkBoxList

    var cboxs = $("#cblAuth input[type=checkbox]"); ; ; i < cboxs.length; i++) { if (cboxs[ ...

  3. NASNet学习笔记——   核心一:延续NAS论文的核心机制使得能够自动产生网络结构;    核心二:采用resnet和Inception重复使用block结构思想;    核心三:利用迁移学习将生成的网络迁移到大数据集上提出一个new search space。

    from:https://blog.csdn.net/xjz18298268521/article/details/79079008 NASNet总结 论文:<Learning Transfer ...

  4. selenium总结

    个人对selenium的理解: 1.使用selenium操作浏览器,实际上是使用selenium框架下的webdriver启动各浏览器的驱动实现对浏览器的操作的.以下两句代码即可启动firefox浏览 ...

  5. 网络编程学习笔记-MAC地址和IP地址的关系

    简单地说:ip地址是服务商给你的,mac地址是你的网卡物理地址. 一.IP地址 对于IP地址,相信大家都很熟悉,即指使用TCP/IP协议指定给主机的32位地址.IP地址由用点分隔开的4个8八位组构成, ...

  6. 「HNOI2008」「LuoguP3197」越狱(数论

    题目描述 原题来自:HNOI 2008 监狱有连续编号为 111 到 nnn 的 nnn 个房间,每个房间关押一个犯人.有 mmm 种宗教,每个犯人可能信仰其中一种.如果相邻房间的犯人信仰的宗教相同, ...

  7. Codefoeces 734F. Anton and School 数学

    Codefoeces 734F 题目大意: 给定两个正整数序列\(b,c\)构造一个正整数序列\(a\)使其满足 \[ \left\{ \begin{array}{} b_i=(a_i\text{ a ...

  8. windwos 10 谷歌浏览器出现彩色闪条

    应该是上个星期五开始,发现电脑从别的地方切换到谷歌浏览器就会出现闪条,开始也没太注意,但是到周一还是这样,所以再网上查了下, 说什么的都有,什么你按脑屏幕坏了,内存条不行什么是的.后来才发现原来是谷歌 ...

  9. 【旧文章搬运】VC插件中如何获取当前工程的工作目录

    原文发表于百度空间,2014-09-24========================================================================== 好难找的资 ...

  10. 异常:Error: Aesthetics must either be length one, or the same length as the dataProblems:AData

    今天遇到一个异常,代码如下: set.seed(12345) require(ggplot2) AData <- data.frame(Glabel=LETTERS[1:7], A=rnorm( ...