D. Longest Subsequence
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given array a with
n elements and the number m. Consider some subsequence of
a and the value of least common multiple (LCM) of its elements. Denote LCM as
l. Find any longest subsequence of
a with the value l ≤ m.

A subsequence of a is an array we can get by erasing some elements of
a. It is allowed to erase zero or all elements.

The LCM of an empty array equals 1.

Input

The first line contains two integers n and
m (1 ≤ n, m ≤ 106) — the size of the array
a and the parameter from the problem statement.

The second line contains n integers
ai (1 ≤ ai ≤ 109) — the elements of
a.

Output

In the first line print two integers l and
kmax (1 ≤ l ≤ m, 0 ≤ kmax ≤ n) — the value of LCM and the number of elements
in optimal subsequence.

In the second line print kmax integers — the positions of the elements from the optimal subsequence in the ascending order.

Note that you can find and print any subsequence with the maximum length.

Examples
Input
7 8
6 2 9 2 7 2 3
Output
6 5
1 2 4 6 7
Input
6 4
2 2 2 3 3 3
Output
2 3

1 2 3


/*题目大意:给定n大小的数组a,求数组a的最长子序列的最小公倍数不超过m。要求输出其满足要求的任意子序列
*算法分析:先将小于等于m的数择出来,然后从后向前筛
*/
#include <bits/stdc++.h>
using namespace std; typedef long long int llint;
const int maxn = 1e6 + 100;
llint a[maxn], b[maxn]; int main() {
memset(a, 0, sizeof(a));
memset(b, 0, sizeof(b));
llint n, m, flag = 0;
scanf("%I64d%I64d",&n, &m);
for (llint i = 0; i<n; i++) {
scanf("%I64d",&a[i]);
if (a[i] <= m) {
b[a[i]] ++ ;
flag = 1;
}
}
if (!flag) cout << "1 0" << endl;
else {
for (llint i = m; i>=1; i--) {
for (llint j = 2*i; j<=m; j+=i) {
b[j] += b[i];
}
}
llint max = 0, lcm = 0;
for (llint i = 1; i<=m; i++) {
if (b[i] > max) {
max = b[i];
lcm = i;
}
}
cout << lcm << " " << max << endl;
for (llint i = 0; i<n; i++) {
if (lcm%a[i] == 0) cout << i+1 << " " ;
}
cout << endl;
}
return 0;
}

D. Longest Subsequence的更多相关文章

  1. Codeforces 632D Longest Subsequence 2016-09-28 21:29 37人阅读 评论(0) 收藏

    D. Longest Subsequence time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  2. Educational Codeforces Round 9 D - Longest Subsequence

    D - Longest Subsequence 思路:枚举lcm, 每个lcm的答案只能由他的因子获得,类似素数筛搞一下. #include<bits/stdc++.h> #define ...

  3. CF632D Longest Subsequence

    D. Longest Subsequence time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  4. Educational Codeforces Round 9 D. Longest Subsequence dp

    D. Longest Subsequence 题目连接: http://www.codeforces.com/contest/632/problem/D Description You are giv ...

  5. [徐州网络赛]Longest subsequence

    [徐州网络赛]Longest subsequence 可以分成两个部分,前面相同,然后下一个字符比对应位置上的大. 枚举这个位置 用序列自动机进行s字符串的下标转移 注意最后一个字符 #include ...

  6. codeforces632D. Longest Subsequence (最小公倍数)

    You are given array a with n elements and the number m. Consider some subsequence of a and the value ...

  7. codeforces 632D. Longest Subsequence 筛法

    题目链接 记录小于等于m的数出现的次数, 然后从后往前筛, 具体看代码. #include <iostream> #include <vector> #include < ...

  8. CodeForces 632D Longest Subsequence

    暴力. 虽然$a[i]$最大有${10^9}$,但是$m$最大只有${10^6}$,因此可以考虑暴力. 记$cnt[i]$表示数字$i$有$cnt[i]$个,记$p[i]$表示以$i$为倍数的情况下, ...

  9. hihoCoder week227 Longest Subsequence

    题目链接 https://hihocoder.com/contest/hiho227/problem/1 题目详解 https://hihocoder.com/discuss/question/558 ...

随机推荐

  1. 排查程序死循环,死锁的方法 ——pstack

    pstack命令可显示每个进程的栈跟踪,pstack $pid即可,pstack命令须由$pid进程的属主或者root运行. 这次出现cpu占比100%的情况,但看memory占比,并无异常,怀疑是某 ...

  2. js回到顶部------转载

    [1]锚点 使用锚点链接是一种简单的返回顶部的功能实现.该实现主要在页面顶部放置一个指定名称的锚点链接,然后在页面下方放置一个返回到该锚点的链接,用户点击该链接即可返回到该锚点所在的顶部位置 [注意] ...

  3. qrc资源文件加载后,裸机环境下图片不显示

    问题描述:在qt开发环境下,使用qss进行界面美化工作,里面包含许多图片资源.最后项目决定把这些图片资源和代码一起打包.然后就把图片资源和qss文件一起编入qrc文件中进行编译.在本机开发环境下是没有 ...

  4. 使用 PyCharm 添加 第三方 依赖库

    背景 最近开始搞python, 需要帮助算法同事一起调试程序,在本地安装python以后使用 pip 来安装第三方库. 但是算法同事一直使用的是PyCharm 这个IDE,所以需要与他一起调试的时候也 ...

  5. JMeter集合点

    位置:添加--> 定时器-->Synchronizing Timer     注意:集合点放在所有操作之前.   假设线程组线程数设置的是50个,那么希望50个都准备好一块上,那么集合点中 ...

  6. 房上的猫:java基础知识部分知识点

    1.Java常见的注释有哪些,语法是怎样的? 1)单行注释用//表示,编译器看到//会忽略该行//后的所文本  2)多行注释/* */表示,编译器看到/*时会搜索接下来的*/,忽略掉/* */之间的文 ...

  7. golang map

    Our friend Monk has been made teacher for the day today by his school professors . He is going to te ...

  8. CRUL学习记录

    在学习web相关知识的时候,了解到crul可以对网址进行请求,并可以看到网站的响应. 1.curl获取web网站返回的网页内容 命令:curl http://XXXXX 2.curl查看web网站的s ...

  9. Python之旅本地环境搭建

    刚开始学习Python, 之后将会把Python相关的一些学习在此记录下来 . 毋庸置疑 ,我们需要先搭建本地开发环境, 为之后的Python开发做准备 ,这篇文章 ,将环境的搭建记录下来 第一步: ...

  10. Koa2和相关资料

    koa2是什么我就不介绍,这里只是收集一些有用的资料,koa这里默认就指koa2了额. koa介绍 koa(GitHub) koa(npm) 文档 Usage Guide Error Handling ...