From 7df3cbab14de7bd9b3eac3884433e31f2cf77866 Mon Sep 17 00:00:00 2001 From: oncsr Date: Sat, 8 Mar 2025 18:28:09 +0900 Subject: [PATCH] =?UTF-8?q?[20250308]=20BOJ=20/=20G2=20/=20MEX=20/=20?= =?UTF-8?q?=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/202503/08 BOJ G2 MEX.md | 82 ++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 khj20006/202503/08 BOJ G2 MEX.md diff --git a/khj20006/202503/08 BOJ G2 MEX.md b/khj20006/202503/08 BOJ G2 MEX.md new file mode 100644 index 00000000..ddbe5d96 --- /dev/null +++ b/khj20006/202503/08 BOJ G2 MEX.md @@ -0,0 +1,82 @@ +## JAVA +```java + +import java.util.*; +import java.io.*; + + +class Main { + + // IO field + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + static StringTokenizer st; + + static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());} + static int nextInt() {return Integer.parseInt(st.nextToken());} + static long nextLong() {return Long.parseLong(st.nextToken());} + static void bwEnd() throws Exception {bw.flush();bw.close();} + + // Additional field + + static int N; + static boolean[] A = new boolean[2200001]; + static boolean[] B = new boolean[2200001]; + + public static void main(String[] args) throws Exception { + + ready(); + solve(); + + bwEnd(); + + } + + static void ready() throws Exception{ + + N = Integer.parseInt(br.readLine()); + for(nextLine();N-->0;A[nextInt()]=true); + + } + + static void solve() throws Exception{ + + for(int i=0;i<=2200000;i++) { + if(!A[i] && !B[i]){ + bw.write(i + "\n"); + return; + } + if(i<2 || !A[i]) continue; + for(long j=i*2;j<=Math.min(2200000L,(long)i*i);j+=i) B[(int)j] = true; + } + + } + +} + +``` + +## C++ +```cpp + +#include +#include +using namespace std; +using ll = long long; + +int main() { + cin.tie(0)->sync_with_stdio(0); + + int N; + cin>>N; + bitset<2200001> A, B; + for(int a;N--;A[a]=1) cin>>a; + for(int i=0;i<2200001;i++) { + if(!A[i] && !B[i]) return cout<