【题目链接】

点击打开链接

【算法】

设取的所有数都是k的约数,则这些数的lcm必然不大于k。

对于[1, m]中的每个数,统计a中有多少个数是它的约数即可。

【代码】

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. const ll MAXN = 1e6;
  5.  
  6. ll i,j,tmp,num,maxx,n,m,res;
  7. ll a[MAXN+],sum[MAXN+],h[MAXN+];
  8. vector<ll> ans;
  9.  
  10. template <typename T> inline void read(T &x) {
  11. ll f = ; x = ;
  12. char c = getchar();
  13. for (; !isdigit(c); c = getchar()) { if (c == '-') f = -f; }
  14. for (; isdigit(c); c = getchar()) x = x * + c - '';
  15. x *= f;
  16. }
  17.  
  18. template <typename T> inline void write(T x) {
  19. if (x < ) { putchar('-'); x = -x; }
  20. if (x > ) write(x/);
  21. putchar(x%+'');
  22. }
  23.  
  24. template <typename T> inline void writeln(T x) {
  25. write(x);
  26. puts("");
  27. }
  28.  
  29. inline ll gcd(ll x,ll y) { return y == ? x : gcd(y,x%y); }
  30.  
  31. int main() {
  32.  
  33. read(n); read(m);
  34. for (i = ; i <= n; i++) {
  35. read(a[i]);
  36. if (a[i] <= m)
  37. ++h[a[i]];
  38. }
  39. for (i = ; i <= m; i++) {
  40. tmp = i;
  41. if (!h[i]) continue;
  42. for (j = tmp; j <= m; j += tmp) {
  43. sum[j] += h[i];
  44. }
  45. }
  46. for (i = ; i <= m; i++) {
  47. if (sum[i] > maxx) {
  48. maxx = sum[i];
  49. num = i;
  50. }
  51. }
  52.  
  53. if (!num) {
  54. printf("1 0\n");
  55. return ;
  56. }
  57.  
  58. for (i = ; i <= n; i++) {
  59. if (!(num % a[i]))
  60. ans.push_back(i);
  61. }
  62.  
  63. res = a[ans[]];
  64. for (i = ; i < ans.size(); i++) res = res * a[ans[i]] / gcd(res,a[ans[i]]);
  65. write(res); putchar(' '); write(ans.size()); puts("");
  66. for (i = ; i < ans.size(); i++) {
  67. write(ans[i]);
  68. if (i < ans.size() - ) putchar(' ');
  69. }
  70.  
  71. return ;
  72.  
  73. }

【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构建游戏服务器(二)--Hello World

    一,准备工作 1,netty-all-4.1.5.Final.jar(官网下载) 2,eclipse 二,步骤概要 1,服务器开发 (1),创建Server类 该类是程序的主入口,有main方法,服务 ...

  2. HDU 5893 List wants to travel(树链剖分+线段树)

    题目链接 HDU5893 $2016$年$ICPC$沈阳网络赛的$B$题.这道题其和 BZOJ2243 基本一样 那道题我也写了题解 点这里 两道题的区别就是$BZOJ$这题是点的权值,这道题是边权. ...

  3. @OneToMany

    实体关系之@OneToMany 博客分类: hibernate & ejb SQL  Order.java package com.entity; import java.io.Seriali ...

  4. Vue1.x 迁移 Vue2.x(项目进行不断修改)

    一.$dispatch 和 $broadcast 已经被弃用. 请使用更多简明清晰的组件间通信和更好的状态管理方案,如:Vuex 这些方法的最常见用途之一是父子组件的相互通信.在这些情况下,你可以使用 ...

  5. Linux线上系统程序debug思路及方法

    http://blog.csdn.net/wangzuxi/article/details/44766221

  6. 实现uitable cell中点击button设置当前cell为选中状态

    - (void)buttonClick:(id)senser{    NSInteger tag = [senser tag];    NSLog(@"the button tag is % ...

  7. 伙伴算法与slab算法

    伙伴算法: 1.将空闲页面分为m个组,第1组存储2^0个单位的内存块,,第2组存储2^1个单位的内存块,第3组存储2^2个单位的内存块,第4组存储2^3个单位的内存块,以此类推.直到m组. 2.每个组 ...

  8. [Adobe Analytics] Segments types

    There are three types of Segmentation Hit-based Visit-based Visitor-based There are four segment con ...

  9. VS2013 update4+Cocos2d-x 3.7 Win8下安装方法及配置

    1.安装VS 2013 update4 7个G.自己就去网上找吧,一大堆,密钥问度娘. 2.安装及配置python 2.x 这里注意,一定要下载python 3.0下面的版本号. 配置:进行环境变量配 ...

  10. SpringBoot学习之快速入门创建

    maven构建项目 1.访问http://start.spring.io/,进入快速创建工程的主页 可参考下图所示: 2.选择构建工具Maven Project.Spring Boot版本1.3.6以 ...