File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed
Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change 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+ ```
You can’t perform that action at this time.
0 commit comments