Skip to content

Commit 64df9de

Browse files
authored
Merge pull request #667 from AlgorithmWithGod/suyeun84
[20250815] BOJ / G5 / 같은 나머지 / 김수연
2 parents a98a326 + b7d331a commit 64df9de

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
```java
2+
import java.io.*;
3+
import java.util.*;
4+
5+
public class boj1684 {
6+
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
7+
static StringTokenizer st;
8+
static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());}
9+
static int nextInt() {return Integer.parseInt(st.nextToken());}
10+
11+
public static void main(String[] args) throws Exception {
12+
nextLine();
13+
int n = nextInt();
14+
int[] arr = new int[n];
15+
nextLine();
16+
for (int i = 0; i < n; i++) arr[i] = nextInt();
17+
Arrays.sort(arr);
18+
int min = arr[0];
19+
int i = 0;
20+
for (i = 0; i < n; i++) if ((arr[i] -= min) != 0) break;
21+
if (i == n) {
22+
System.out.println(min);
23+
return;
24+
}
25+
int gcd = arr[i++];
26+
for (; i < n; i++) gcd = gcd(gcd, arr[i]-=min);
27+
System.out.println(gcd);
28+
}
29+
30+
static int gcd(int a, int b) {
31+
int r = -1;
32+
while (r!=0) {
33+
r = a % b;
34+
a = b;
35+
b = r;
36+
}
37+
return a;
38+
}
39+
}
40+
```

0 commit comments

Comments
 (0)