From f5c6f27989837c440e92d6c3cb93edb4ebce01af Mon Sep 17 00:00:00 2001 From: oncsr Date: Fri, 20 Jun 2025 22:13:30 +0900 Subject: [PATCH] =?UTF-8?q?[20250620]=20BOJ=20/=20P4=20/=20blobfearful=20/?= =?UTF-8?q?=20=EA=B6=8C=ED=98=81=EC=A4=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- khj20006/202506/20 BOJ P4 blobfearful.md | 115 +++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 khj20006/202506/20 BOJ P4 blobfearful.md diff --git a/khj20006/202506/20 BOJ P4 blobfearful.md b/khj20006/202506/20 BOJ P4 blobfearful.md new file mode 100644 index 00000000..3bcaf366 --- /dev/null +++ b/khj20006/202506/20 BOJ P4 blobfearful.md @@ -0,0 +1,115 @@ +```java +import java.math.BigInteger; +import java.util.*; +import java.io.*; + +class IOController { + BufferedReader br; + BufferedWriter bw; + StringTokenizer st; + + public IOController() { + br = new BufferedReader(new InputStreamReader(System.in)); + bw = new BufferedWriter(new OutputStreamWriter(System.out)); + st = new StringTokenizer(""); + } + + String nextLine() throws Exception { + String line = br.readLine(); + st = new StringTokenizer(line); + return line; + } + + String nextToken() throws Exception { + while (!st.hasMoreTokens()) nextLine(); + return st.nextToken(); + } + + int nextInt() throws Exception { + return Integer.parseInt(nextToken()); + } + + long nextLong() throws Exception { + return Long.parseLong(nextToken()); + } + + double nextDouble() throws Exception { + return Double.parseDouble(nextToken()); + } + + void close() throws Exception { + bw.flush(); + bw.close(); + } + + void write(String content) throws Exception { + bw.write(content); + } + +} + +public class Main { + + static IOController io; + + // + + static long K, Q; + static HashMap M; + + public static void main(String[] args) throws Exception { + + io = new IOController(); + + init(); + solve(); + + io.close(); + + } + + public static void init() throws Exception { + + K = io.nextLong(); + Q = io.nextInt(); + M = new HashMap<>(); + + } + + static void solve() throws Exception { + + for(long k=2;k*k<=K;k++) if(K%k == 0) { + int cnt = 0; + while(K%k == 0){ + K/=k; + cnt++; + } + M.put(k, cnt); + } + if(K != 1) M.put(K, 1); + + while(Q-->0) { + long a = io.nextLong(); + long ans = 0; + for(long i:M.keySet()) { + long temp = a; + int cnt = 0; + while(temp%i == 0){ + temp /= i; + cnt++; + } + cnt = Math.max(0, M.get(i) - cnt); + long res = 0, count = 0; + while(count < cnt) { + res += i; + for(long j = i;j<=res;j*=i) if(res % j == 0) count++; + } + ans = Math.max(ans, res); + } + io.write(ans + " "); + } + + } + +} +```