【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 ...
随机推荐
- WebGIS开发之用openlayers加载离线百度地图
因为项目需要,只有内网环境,没有外网环境,所以需要下载地图瓦片. 一.下载瓦片地图 这个可以自行在网上找一些地图瓦片下载器,下好的瓦片地图是分级的.大概如图这种类型. 二.在地图上显示标记 首先使用o ...
- iOS开发 检测版本更新
iOS开发 检测版本更新的实现 苹果给了我们一个接口,能根据应用id请求一些关于应用的信息.我们可以根据返回的信息,来判断版本是否和应用的版本一致,如果不一致,那么就出现新的版本了.这时,就需要向用户 ...
- 第24章、OnLongClickListener长按事件(从零开始学Android)
在Android App应用中,OnLongClick事件表示长按2秒以上触发的事件,本章我们通过长按图像设置为墙纸来理解其具体用法. 知识点:OnLongClickListener OnLongCl ...
- wiki平台工具
1. confluence 评点: 好用,与world类似.模板多.
- cocos2d-x 3.0 引用第三方库 及编译成apk时android mk文件写法
cocos2d-x 3.0 中.假设你须要使用CocosStudio.Extensions扩展库 等等.都须要自己手动加入. 加入过程例如以下:(比方说如今我要加入libExtensions,libC ...
- eclipse 配置执行hadoop 2.7 程序样例參考步骤
前提:你搭建好了hadoop 2.x的linux环境,并可以成功执行.还有就是window可以訪问到集群.over 1. hfds-site.xml 添加属性:关闭集群的权限校验.windows的用户 ...
- C#语言 循环语句
//Console.Write("请输入关卡数:"); //int a = int.Parse(Console.ReadLine()); //int s = 0; //if (a ...
- 【转载】C#扫盲之:静态成员、静态方法、静态类、实例成员及区别
文章目录 1.静态成员.实例成员 2.静态类 3.类的静态成员和非静态成员区别 --------------------------------------分割线------------------- ...
- CPU die
http://en.wikipedia.org/wiki/CPU_Die Die (integrated circuit) From Wikipedia, the free encyclopedia ...
- Ubuntu安装教程--Win7系统中含100M保留分区
1.检查 Win7 保留分区 1)进入 Win7 打开库目录.在左側栏找到"计算机",瞄准点右键选择"管理"菜单: 2)在出来的管理面板左边找到"磁盘 ...