From b7d331ae97ce4da12b5ffd86bc1483be1cf642c2 Mon Sep 17 00:00:00 2001 From: suyeun84 <81475092+suyeun84@users.noreply.github.com> Date: Fri, 15 Aug 2025 17:45:47 +0900 Subject: [PATCH] =?UTF-8?q?[20250815]=20BOJ=20/=20G5=20/=20=EA=B0=99?= =?UTF-8?q?=EC=9D=80=20=EB=82=98=EB=A8=B8=EC=A7=80=20/=20=EA=B9=80?= =?UTF-8?q?=EC=88=98=EC=97=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0 \353\202\230\353\250\270\354\247\200.md" | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 "suyeun84/202508/15 BOJ G5 \352\260\231\354\235\200 \353\202\230\353\250\270\354\247\200.md" diff --git "a/suyeun84/202508/15 BOJ G5 \352\260\231\354\235\200 \353\202\230\353\250\270\354\247\200.md" "b/suyeun84/202508/15 BOJ G5 \352\260\231\354\235\200 \353\202\230\353\250\270\354\247\200.md" new file mode 100644 index 00000000..74056f08 --- /dev/null +++ "b/suyeun84/202508/15 BOJ G5 \352\260\231\354\235\200 \353\202\230\353\250\270\354\247\200.md" @@ -0,0 +1,40 @@ +```java +import java.io.*; +import java.util.*; + +public class boj1684 { + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static StringTokenizer st; + static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());} + static int nextInt() {return Integer.parseInt(st.nextToken());} + + public static void main(String[] args) throws Exception { + nextLine(); + int n = nextInt(); + int[] arr = new int[n]; + nextLine(); + for (int i = 0; i < n; i++) arr[i] = nextInt(); + Arrays.sort(arr); + int min = arr[0]; + int i = 0; + for (i = 0; i < n; i++) if ((arr[i] -= min) != 0) break; + if (i == n) { + System.out.println(min); + return; + } + int gcd = arr[i++]; + for (; i < n; i++) gcd = gcd(gcd, arr[i]-=min); + System.out.println(gcd); + } + + static int gcd(int a, int b) { + int r = -1; + while (r!=0) { + r = a % b; + a = b; + b = r; + } + return a; + } +} +```