【题目链接】

点击打开链接

【算法】

设取的所有数都是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的更多相关文章

  1. 【29.41%】【codeforces 724D】Dense Subsequence

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  2. 【Codeforces 977F】Consecutive Subsequence

    [链接] 我是链接,点我呀:) [题意] 题意 [题解] 设f[i]表示i作为序列的最后一个数字,最长的连续序列的长度. 用f[i]和f[i-1]+1来转移即可 [代码] import java.io ...

  3. 【CodeForces 616D】Longest k-Good Segment

    题意 n个数里,找到最长的一个连续序列使里面最多k个不同的数. 分析 尺取法,每次R++,如果第R个数未出现过,那么不同的数+1,然后这个数的出现次数+1,如果不同的数大于k了,那就要去掉第L个数,直 ...

  4. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  5. 【codeforces 766A】Mahmoud and Longest Uncommon Subsequence

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  6. 【codeforces 750E】New Year and Old Subsequence

    time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  7. 【33.10%】【codeforces 604C】Alternative Thinking

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  8. 【17.07%】【codeforces 583D】Once Again...

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  9. 【32.22%】【codeforces 602B】Approximating a Constant Range

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

随机推荐

  1. (4)Swing布局

    一.FlowLayout-流布局 新增第一个组件后默认在第一行的居中位置,之后 组件按照加入的先后顺序按照设置的对齐方式从左向右排列 二.borderLayout-边框布局 容器划分为东.西.南.北. ...

  2. NFV产品如何才能走向规模商用

    作者简介:王晔,烽火通信科技股份有限公司ICT网络产品线NFV产品总监,高级工程师,研究方向为SDN\NFV\MEC\AI\光通信. 自2013年AT&T率先提出DOMAIN 2.0网络转型计 ...

  3. Liunx 下Redis 的安装

    一.Redis 的简介 Redis是一款开源的.高性能的键-值存储.它常被称作是一款数据结构服务器,它是一个key-value存储系统.和Memcache类似,Memecache只支持字符窜的数据类型 ...

  4. chrome备份网站

    chrome备份网站 https://www.chromedownloads.net/

  5. SQL经常使用语法

    一.基础 1.创建数据库 CREATE DATABASE database-name 2.删除数据库 drop database dbname 3.备份sql server --- 创建 备份数据的 ...

  6. 【Jqurey EasyUI+Asp.net】----DataGrid数据绑定,以及增、删、改(SQL)

    也懒得打其他字了,直接进入主题吧 1.首先,数据表Rex_Test ID int 自增 tName varchar(10) 姓名 tEmail varchar(80) 邮箱 2.至于代码里的Jqure ...

  7. PHP读取excel(6)

    有时候我们只需要读取某些指定sheet,具体代码如下: <?php header("Content-Type:text/html;charset=utf-8"); //引入读 ...

  8. LeetCode_3Sum

    一.题目 3Sum Total Accepted: 45112 Total Submissions: 267165My Submissions Given an array S of n intege ...

  9. UUID GUID

    http://baike.baidu.com/link?url=xkck9gR5bzOx0oBKP1qNJwGGq3IO56V4i8cg9zTSpSDMVBMA0F7jr0AdkQTGyk7F0FGj ...

  10. 不能选择sublime作为默认打开方式的解决办法

    Sublime Text 绿色版删除后无法设置为默认打开方式…而且网上也没有给出明确的解决办法 注册表的解决办法: 删除 HKEY_CURRENT_USER\Software\Classes\Appl ...