-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTask632D.java
More file actions
53 lines (47 loc) · 1.46 KB
/
Task632D.java
File metadata and controls
53 lines (47 loc) · 1.46 KB
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
import java.util.*;
import java.io.*;
public class Task632D {
public static void main(String[] args) throws Exception {
Scanner s = new Scanner(System.in);
BufferedReader rdr = new BufferedReader(new InputStreamReader(System.in));
String[] strs = rdr.readLine().split(" ");
int n = Integer.parseInt(strs[0]);
int m = Integer.parseInt(strs[1]);
strs = rdr.readLine().split(" ");
int[] in = new int[n];
for(int i = 0; i < n; i++) {
in[i] = Integer.parseInt(strs[i]);
}
int[] counts = new int[m + 1];
for(int i = 0; i < n; i++) {
if(in[i] <= m) {
counts[in[i]]++;
}
}
int[] divisors = new int[m + 1];
for(int i = 1; i <= m; i++) {
if(counts[i] > 0) {
for(int k = i; k <= m; k += i) {
divisors[k] += counts[i];
}
}
}
int mlcm = 0;
int l = 1;
for(int i = 0; i <= m; i++) {
if(mlcm < divisors[i]) {
mlcm = divisors[i];
l = i;
}
}
System.out.println(l + " " + mlcm);
PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));
for(int i = 0; i < n; i++) {
if(l % in[i] == 0) {
pw.print( (i + 1) + " ");
}
}
pw.println("");
pw.flush();
}
}