Skip to content

Commit 78ffa28

Browse files
authored
Merge pull request #890 from AlgorithmWithGod/khj20006
[20250914] BOJ / P5 / 서커스 나이트 / 권혁준
2 parents f552e50 + 08bb0e5 commit 78ffa28

File tree

1 file changed

+106
-0
lines changed

1 file changed

+106
-0
lines changed
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
```java
2+
import java.io.*;
3+
import java.util.*;
4+
5+
class IOController {
6+
BufferedReader br;
7+
BufferedWriter bw;
8+
StringTokenizer st;
9+
10+
public IOController() {
11+
br = new BufferedReader(new InputStreamReader(System.in));
12+
bw = new BufferedWriter(new OutputStreamWriter(System.out));
13+
st = new StringTokenizer("");
14+
}
15+
16+
String nextLine() throws Exception {
17+
String line = br.readLine();
18+
st = new StringTokenizer(line);
19+
return line;
20+
}
21+
22+
String nextToken() throws Exception {
23+
while (!st.hasMoreTokens())
24+
nextLine();
25+
return st.nextToken();
26+
}
27+
28+
int nextInt() throws Exception {
29+
return Integer.parseInt(nextToken());
30+
}
31+
32+
long nextLong() throws Exception {
33+
return Long.parseLong(nextToken());
34+
}
35+
36+
double nextDouble() throws Exception {
37+
return Double.parseDouble(nextToken());
38+
}
39+
40+
void close() throws Exception {
41+
bw.flush();
42+
bw.close();
43+
}
44+
45+
void write(String content) throws Exception {
46+
bw.write(content);
47+
}
48+
49+
}
50+
51+
public class Main {
52+
53+
static IOController io;
54+
55+
//
56+
57+
static int N;
58+
static int[] a, c, r, e;
59+
60+
static int f(int x) {return x == r[x] ? x : (r[x]=f(r[x]));}
61+
62+
public static void main(String[] args) throws Exception {
63+
64+
io = new IOController();
65+
66+
N = io.nextInt();
67+
r = new int[1000001];
68+
e = new int[1000001];
69+
for(int i=2;i*i<=1000000;i++) if(e[i] == 0) for(int j=i*i;j<=1000000;j+=i) if(e[j] == 0) e[j] = i;
70+
for(int i=2;i<=1000000;i++) r[i] = i;
71+
c = new int[1000001];
72+
a = new int[N];
73+
for(int i=0;i<N;i++) {
74+
a[i] = io.nextInt();
75+
c[a[i]]++;
76+
}
77+
78+
for(int i=0;i<N;i++) {
79+
int t = a[i];
80+
while(e[t] != 0) {
81+
int x = f(a[i]), y = f(e[t]);
82+
if(x != y) {
83+
c[y] += c[x];
84+
r[x] = y;
85+
}
86+
t /= e[t];
87+
}
88+
if(t != 1) {
89+
int x = f(a[i]), y = f(t);
90+
if(x != y) {
91+
c[y] += c[x];
92+
r[x] = y;
93+
}
94+
}
95+
}
96+
97+
int ans = 0;
98+
for(int i=2;i<=1000000;i++) ans = Math.max(ans, c[f(i)]);
99+
io.write(ans + "\n");
100+
101+
io.close();
102+
103+
}
104+
105+
}
106+
```

0 commit comments

Comments
 (0)