diff --git "a/khj20006/202509/14 BOJ P5 \354\204\234\354\273\244\354\212\244 \353\202\230\354\235\264\355\212\270.md" "b/khj20006/202509/14 BOJ P5 \354\204\234\354\273\244\354\212\244 \353\202\230\354\235\264\355\212\270.md" new file mode 100644 index 00000000..da99e4cf --- /dev/null +++ "b/khj20006/202509/14 BOJ P5 \354\204\234\354\273\244\354\212\244 \353\202\230\354\235\264\355\212\270.md" @@ -0,0 +1,106 @@ +```java +import java.io.*; +import java.util.*; + +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 int N; + static int[] a, c, r, e; + + static int f(int x) {return x == r[x] ? x : (r[x]=f(r[x]));} + + public static void main(String[] args) throws Exception { + + io = new IOController(); + + N = io.nextInt(); + r = new int[1000001]; + e = new int[1000001]; + 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; + for(int i=2;i<=1000000;i++) r[i] = i; + c = new int[1000001]; + a = new int[N]; + for(int i=0;i