【题目链接】

点击打开链接

【算法】

设取的所有数都是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. Netty构建游戏服务器(三)--netty spring简单整合

    一,基本方法 上节实现了netty的基本连接,这节加入spring来管理netty,由spring来开启netty服务. 在netty服务器中,我们建立了三个类:HelloServer(程序主入口) ...

  2. [Bzoj3172][Tjoi2013]单词(fail树)

    3172: [Tjoi2013]单词 Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 4777  Solved: 2345[Submit][Status ...

  3. Java中的网络基础

    先来一张图记录一下大概思路,之后再更新具体的代码实现.基本上来说,前半部分自己会编写一个基于socket编程的多客户端dos聊天服务器,后半部分可以实现与已有的一些服务器(比如www.google.c ...

  4. [vxlan] 二 什么是VXLAN

    VXLAN是一种mac in UDP的技术.简单讲就是传统的二层帧被封装到了UDP的package中.通过UDP的IP网络发送到目的地然后再解封装. VXLAN 跟VLAN对比,最重要的一个概念就是V ...

  5. Obj-C, library with ARC code and warning - Method possibly missing a [super dealloc] call?

    1 down vote favorite I'm adding the MKStoreKit to my app and I'm getting a warning, Method possibly ...

  6. python遍历两个列表,若长度不等,用None填充

    zip经常会遇到截断问题,如:a = [1,2,3], b = [4,5,6,7],则zip(a,b) = [(1, 4), (2, 5), (3, 6)] 可考虑使用map: map(lambda ...

  7. 静态NAT、动态NAT、PAT(端口多路复用)的配置

    静态NAT.动态NAT.PAT(端口多路复用)的配置   NAT的实现方式有三种,即静态转换Static Nat.动态转换Dynamic Nat 和 端口多路复用OverLoad.    静态转换 ( ...

  8. ElasticSearch集群本机搭建

    ElasticSearch集群本机搭建 elasticsearch elasticsearch -Ehttp.port=8200 -Epath.data=node2 elasticsearch -Eh ...

  9. ShopMall

    https://github.com/KingsleyYau/ShopMall-Android https://github.com/KingsleyYau/ShopMall-iOS https:// ...

  10. HDU 3639 Hawk-and-Chicken

    Hawk-and-Chicken Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...