Skip to content

Commit f5c6f27

Browse files
authored
[20250620] BOJ / P4 / blobfearful / 권혁준
1 parent 1764ffb commit f5c6f27

File tree

1 file changed

+115
-0
lines changed

1 file changed

+115
-0
lines changed
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
```java
2+
import java.math.BigInteger;
3+
import java.util.*;
4+
import java.io.*;
5+
6+
class IOController {
7+
BufferedReader br;
8+
BufferedWriter bw;
9+
StringTokenizer st;
10+
11+
public IOController() {
12+
br = new BufferedReader(new InputStreamReader(System.in));
13+
bw = new BufferedWriter(new OutputStreamWriter(System.out));
14+
st = new StringTokenizer("");
15+
}
16+
17+
String nextLine() throws Exception {
18+
String line = br.readLine();
19+
st = new StringTokenizer(line);
20+
return line;
21+
}
22+
23+
String nextToken() throws Exception {
24+
while (!st.hasMoreTokens()) 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 long K, Q;
58+
static HashMap<Long, Integer> M;
59+
60+
public static void main(String[] args) throws Exception {
61+
62+
io = new IOController();
63+
64+
init();
65+
solve();
66+
67+
io.close();
68+
69+
}
70+
71+
public static void init() throws Exception {
72+
73+
K = io.nextLong();
74+
Q = io.nextInt();
75+
M = new HashMap<>();
76+
77+
}
78+
79+
static void solve() throws Exception {
80+
81+
for(long k=2;k*k<=K;k++) if(K%k == 0) {
82+
int cnt = 0;
83+
while(K%k == 0){
84+
K/=k;
85+
cnt++;
86+
}
87+
M.put(k, cnt);
88+
}
89+
if(K != 1) M.put(K, 1);
90+
91+
while(Q-->0) {
92+
long a = io.nextLong();
93+
long ans = 0;
94+
for(long i:M.keySet()) {
95+
long temp = a;
96+
int cnt = 0;
97+
while(temp%i == 0){
98+
temp /= i;
99+
cnt++;
100+
}
101+
cnt = Math.max(0, M.get(i) - cnt);
102+
long res = 0, count = 0;
103+
while(count < cnt) {
104+
res += i;
105+
for(long j = i;j<=res;j*=i) if(res % j == 0) count++;
106+
}
107+
ans = Math.max(ans, res);
108+
}
109+
io.write(ans + " ");
110+
}
111+
112+
}
113+
114+
}
115+
```

0 commit comments

Comments
 (0)