【Codeforces 632D】 Longest Subsequence
【题目链接】
【算法】
设取的所有数都是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的更多相关文章
- 【29.41%】【codeforces 724D】Dense Subsequence
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【Codeforces 977F】Consecutive Subsequence
[链接] 我是链接,点我呀:) [题意] 题意 [题解] 设f[i]表示i作为序列的最后一个数字,最长的连续序列的长度. 用f[i]和f[i-1]+1来转移即可 [代码] import java.io ...
- 【CodeForces 616D】Longest k-Good Segment
题意 n个数里,找到最长的一个连续序列使里面最多k个不同的数. 分析 尺取法,每次R++,如果第R个数未出现过,那么不同的数+1,然后这个数的出现次数+1,如果不同的数大于k了,那就要去掉第L个数,直 ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【codeforces 766A】Mahmoud and Longest Uncommon Subsequence
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 750E】New Year and Old Subsequence
time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【33.10%】【codeforces 604C】Alternative Thinking
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【17.07%】【codeforces 583D】Once Again...
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【32.22%】【codeforces 602B】Approximating a Constant Range
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
随机推荐
- PAT (Advanced Level) 1087. All Roads Lead to Rome (30)
暴力DFS. #include<cstdio> #include<cstring> #include<cmath> #include<vector> # ...
- Codechef Yet another cute girl
题意大概就是让你求一下[L,R]中的约数个数是素数的数的个数. 其中1<=L<=R<=1e12,R-L<=1e6. 然后我写了两种做法,第一种是可以直接搞出来L-R的约数个数, ...
- 当传入数据只有一个时mybatis中<if>判断会出现There is no getter for property named 'subjectId' in 'class java.lang.Intege
用"_parameter"代替当前参数 正确: <select id="selectSubjectByPId" parameterType="j ...
- 如何更改ORACLE 用户的 expired状态
ORACLE(113) 版权声明:本文为博主原创文章,未经博主允许不得转载. oracle中, 经常用户的状态会变成locked, expired 等状态, 这种情况下怎么处理呢? 首先, 如果是l ...
- python学习笔记——递归算法
阶乘 #递归计算阶乘 def factorial(n): if n == 1: return 1 return n*factorial(n-1) result = factorial(6) print ...
- ffmpeg实时编码解码部分代码
程序分为编码端和解码端,两端通过tcp socket通信,编码端一边编码一边将编码后的数据发送给解码端.解码端一边接收数据一边将解码得到的帧显示出来. 代码中的编码端编码的是实时屏幕截图. 代码调用 ...
- mmall 项目实战(一)项目初始化
1.创建 数据库 及 表 数据脚本: /* Navicat Premium Data Transfer Source Server : 182.92.82.103 Source Server Type ...
- 终端中的乐趣:6个有趣的Linux命令行工具
文章链接: http://hpw123.net/a/Linux/ruanjiananzhuang/2014/1103/117.html 很多其它文章尽在 http://www.hpw123.net ...
- Desktop Management Interface & System Management BIOS
http://en.wikipedia.org/wiki/Desktop_Management_Interface Desktop Management Interface From Wikipedi ...
- Django-权限信息自定义标签
自定义权限标签: import re from django.template import Library from django.conf import settings register = L ...