【Codeforces 632D】 Longest Subsequence
【题目链接】
【算法】
设取的所有数都是k的约数,则这些数的lcm必然不大于k。
对于[1, m]中的每个数,统计a中有多少个数是它的约数即可。
【代码】
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MAXN = 1e6; ll i,j,tmp,num,maxx,n,m,res;
ll a[MAXN+],sum[MAXN+],h[MAXN+];
vector<ll> ans; template <typename T> inline void read(T &x) {
ll f = ; x = ;
char c = getchar();
for (; !isdigit(c); c = getchar()) { if (c == '-') f = -f; }
for (; isdigit(c); c = getchar()) x = x * + c - '';
x *= f;
} template <typename T> inline void write(T x) {
if (x < ) { putchar('-'); x = -x; }
if (x > ) write(x/);
putchar(x%+'');
} template <typename T> inline void writeln(T x) {
write(x);
puts("");
} inline ll gcd(ll x,ll y) { return y == ? x : gcd(y,x%y); } int main() { read(n); read(m);
for (i = ; i <= n; i++) {
read(a[i]);
if (a[i] <= m)
++h[a[i]];
}
for (i = ; i <= m; i++) {
tmp = i;
if (!h[i]) continue;
for (j = tmp; j <= m; j += tmp) {
sum[j] += h[i];
}
}
for (i = ; i <= m; i++) {
if (sum[i] > maxx) {
maxx = sum[i];
num = i;
}
} if (!num) {
printf("1 0\n");
return ;
} for (i = ; i <= n; i++) {
if (!(num % a[i]))
ans.push_back(i);
} res = a[ans[]];
for (i = ; i < ans.size(); i++) res = res * a[ans[i]] / gcd(res,a[ans[i]]);
write(res); putchar(' '); write(ans.size()); puts("");
for (i = ; i < ans.size(); i++) {
write(ans[i]);
if (i < ans.size() - ) putchar(' ');
} return ; }
【Codeforces 632D】 Longest Subsequence的更多相关文章
- 【29.41%】【codeforces 724D】Dense Subsequence
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【Codeforces 977F】Consecutive Subsequence
[链接] 我是链接,点我呀:) [题意] 题意 [题解] 设f[i]表示i作为序列的最后一个数字,最长的连续序列的长度. 用f[i]和f[i-1]+1来转移即可 [代码] import java.io ...
- 【CodeForces 616D】Longest k-Good Segment
题意 n个数里,找到最长的一个连续序列使里面最多k个不同的数. 分析 尺取法,每次R++,如果第R个数未出现过,那么不同的数+1,然后这个数的出现次数+1,如果不同的数大于k了,那就要去掉第L个数,直 ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【codeforces 766A】Mahmoud and Longest Uncommon Subsequence
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 750E】New Year and Old Subsequence
time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【33.10%】【codeforces 604C】Alternative Thinking
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【17.07%】【codeforces 583D】Once Again...
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【32.22%】【codeforces 602B】Approximating a Constant Range
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
随机推荐
- 2019年北航OO第3单元(JML)总结
1 JML语言的理论基础及应用工具链 1.1 JML语言 Java建模语言(JML)是一种行为接口规范语言,可用于指定Java模块的行为.它结合了Eiffel的"契约设计(design by ...
- iOS 读书笔记 第一章
1.确定某个实例或类方法是否可用. 1)使用NSObject的类方法instancesRespondToSelector:来确定是否在该类的一个实例中存在一个特定的选择器. NSArray *arra ...
- 超级强大的淘宝开源平台(taobao-code)
今天发现了一个免费又高级的开源SVN服务器,taobao,阿里云CODE.迫不及待的注册了一个.感觉不错,分享给大家. 先说说我们用过的几个SVN服务器吧: google code oksvn(感觉不 ...
- es中插入数据
es中插入数据 学习了:https://www.imooc.com/video/15769/0 分为指定Id和自动生成Id两种: 1,指定Id使用PUT操作 PUT http://127.0.0.1: ...
- shell mysql 直接创建表
shell 直接创建表 #!/bin/bash mysql -hdatabases -uroot -p^xxxxasdasdadd <<EOF Create Database If Not ...
- Variable 'bop' is uninitialized when captured by block
代码: - (void)doTest { NSBlockOperation * bop = [NSBlockOperation blockOperationWithBlock:^{ if (!bop. ...
- 【Mongodb教程 第十九课 】PHP与MONGODB的条件查询
与普通的关系型数据库类似,在对数据的删.改.查的时候,会用到查询条件,如mysql中的 where… 而MongoDB中,经过php来做的所有的操作指令都是用array来包裹的: MongoColle ...
- windows下安装elasticsearch6.2.4
window 下安装 elasticsearch 一.环境搭建需要的环境 1.jdk环境 2.Elasticsearch 3.git 环境 4.node 安装包 二.进行环境的搭建 1.解压Ela ...
- Linux 用户和文件权限管理
Linux —— 用户权限管理 权限: 为什么需要权限管理? 1.计算机资源有限,我们需要合理的分配计算机资源. 2.Linux是一个多用户系统,对于每一个用户来说,个人隐私的保护是十分重 ...
- HDU 5371 Hotaru's problem(Manacher算法+贪心)
manacher算法详见 http://blog.csdn.net/u014664226/article/details/47428293 题意:给一个序列,让求其最大子序列,这个子序列由三段组成, ...