-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathD.cpp
64 lines (58 loc) · 1.39 KB
/
D.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <bits/stdc++.h>
#define fi first
#define se second
#define DB double
#define U unsigned
#define P std::pair
#define LL long long
#define LD long double
#define pb push_back
#define MP std::make_pair
#define SZ(x) ((int)x.size())
#define all(x) x.begin(),x.end()
#define CLR(i,a) memset(i,a,sizeof(i))
#define FOR(i,a,b) for(int i = a;i <= b;++i)
#define ROF(i,a,b) for(int i = a;i >= b;--i)
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl
const int MAXN = 1e6 + 5;
int a[MAXN],n,m;
inline int gcd(int x,int y){
return !y ? x : gcd(y,x%y);
}
inline int lcm(int x,int y){
return x/gcd(x,y)*y;
}
std::vector<int> G[MAXN];
int cnt[MAXN];
int main(){
scanf("%d%d",&n,&m);
FOR(i,1,n){
scanf("%d",a+i);
if(a[i] <= m) ++cnt[a[i]],G[a[i]].pb(i);
}
ROF(i,m,1){
for(int j = i;j <= m;j += i){
cnt[j] += cnt[i];
}
}
int ans = 0,ps = -1;
FOR(i,1,m) if(ans < cnt[i]) ans = cnt[i],ps = i;
if(ps == -1){
puts("1 0");
return 0;
}
int q = std::sqrt(1.0*ps);std::vector<int> S;
int l = 1;
FOR(i,1,q){
if(!(ps%i)){
for(auto x:G[i]) S.pb(x);
l = lcm(l,i);
l = lcm(l,ps/i);
if(i != ps/i) for(auto x:G[ps/i]) S.pb(x);
}
}
printf("%d %d\n",l,SZ(S));
std::sort(all(S));
for(auto x:S) printf("%d ",x);puts("");
return 0;
}