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. 【实验手册】使用Visual Studio Code 开发.NET Core应用程序

    .NET Core with Visual Studio Code 目录 概述... 2 先决条件... 2 练习1: 安装和配置.NET Core以及Visual Studio Code 扩展... ...

  2. sed 命令替换字符串

    sed -i 's/13/15/g'  `grep 13 -rl  目录` -i 表示替换 -r 表示搜索子目录 -l 显示替换名

  3. [UWP]了解IValueConverter

    1. 前言 IValueConverter是用于数据绑定的强大的武器,它用于Value在Binding Source和Binding Target之间的转换.本文将介绍IValueConverter的 ...

  4. Web API系列之一 Rest简介

    1.REST:Representational State Transfer表征状态转移,是Roy Fielding博士在2000年他的博士论文中提出来的一种软件架构风格.REST设计风格有如下几点: ...

  5. idea为tomcat设置虚拟地址

    1.设置tomcat的server.xml <Host name="localhost" appBase="webapps" unpackWARs=&qu ...

  6. centos 系统日志

    Linux系统日志主要有三类:连接时间日志.进程统计日志和错误日志 连接时间日志 连接时间日志由多个程序执行,把记录写入到/var/og/wtmp和/var/run/utmp.ogin等程序更新wtm ...

  7. 物联网细分领域-车联网(OBD)市场分析

    前言: 这段时间在跟一个车联网的项目,所以做了一些研究. OBD概述 OBD是英文On-Board Diagnostic的缩写,中文翻译为"车载诊断系统".这个系统随时监控发动机的 ...

  8. SQLServer 发布订阅(Replication)造成的Memroy压力(cmemthread等待)

    深入了解下发布订阅:     数据复制:允许一个数据源向一个或多个目标数据库分发数据,只需要OLE DB 访问接口即可访问: 整个复制框架包含:复制组件,复制代理,复制类型: 复制组件: 发布服务器: ...

  9. Python爬虫知识点一

    一.入门知识: 1.1.HTTP简介HTTP = HyperText Transfer ProtocolURI = Uniform Resource IdentifierURL = Uniform R ...

  10. winform listview用法

    资源收集 C#winform中ListView的使用 C# WinForm开发系列 - ListBox/ListView/Panel(介绍了一些listview的高级用法) 直接上代码 示例一: th ...