我预处理\(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. python学习笔记:第八天(模块)

    Python3 模块 脚本上是用 python 解释器来编程,如果从 Python 解释器退出再进入,那么定义的所有的方法和变量就都消失了. 为此 Python 提供了一个办法,把这些定义存放在文件中 ...

  2. ES 搜索结果expalain 可以类似数据库性能调优来看排序算法的选择

    When we run a simple term query with explain set to true (see Understanding the Score), you will see ...

  3. listen and translation exercise 51

    You are supposed to be having fun now. I have to hand in my biology paper tomorrow. Listen, you litt ...

  4. VC++动态链接库(DLL)编程深入浅出:Q&A(原创)

    Q1:extern “C” 是做什么用的? A1:一种情况是多个文件中,变量声明或者函数声明,需要extern “C”,这种情况在这里不做讨论. 在dll工程中,被extern "C&quo ...

  5. 【LeetCode】064. Minimum Path Sum

    题目: Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right w ...

  6. Python基础入门知识

    本节内容 Python介绍 发展史 Python 2 or 3? 安装 Hello World程序 变量 用户输入 模块初识 .pyc是个什么鬼? 数据类型初识 数据运算 表达式if ...else语 ...

  7. [转]提高 web 应用性能之 CSS 性能调优

    简介 Web 开发中经常会遇到性能的问题,尤其是 Web 2.0 的应用.CSS 代码是控制页面显示样式与效果的最直接“工具”,但是在性能调优时他们通常被 Web 开发工程师所忽略,而事实上不规范的 ...

  8. SimpliciTI协议地址分配

    1.多个ED节点和AP正确连接后,AP都会给ED分配一个相应的地址.当某个ED出现意外,比如电源问题,和AP断开连接,AP并不将该ED节点的地址消除.当该ED恢复正常,重新申请加入网络时,AP会检测该 ...

  9. ie下使用文本编辑器导致input文本框无法聚焦的问题原因

    最近公司的一个项目遇到一个如下问题: 描述:测试发现,每当我们在发布活动的页面发布完活动后,页面跳转到我的活动,然后再次回到发布活动页面,发现所有的input文本框都不能聚焦.然后再去看看其他页面(我 ...

  10. [xdoj1216]子树第k小(dfs序+主席树)

    解题关键:dfs序将树映射到区间,然后主席树求区间第k小,为模板题. #pragma comment(linker, "/STACK:1024000000,1024000000") ...