-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathB2485.java
More file actions
32 lines (25 loc) · 762 Bytes
/
B2485.java
File metadata and controls
32 lines (25 loc) · 762 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package Practice;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class B2485 { //°¡·Î¼ö
static int N;
static int[] trees;
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
N = Integer.parseInt(br.readLine());
trees = new int[N];
for(int i = 0; i < N; i++) trees[i] = Integer.parseInt(br.readLine());
int dis = trees[1] - trees[0];
for(int i = 2; i < N; i++) dis = find_gcd(trees[i] - trees[0], dis);
System.out.println((trees[N - 1] - trees[0]) / dis + 1 - N);
}
static int find_gcd(int a, int b) {
while(a % b != 0) {
int temp = b;
b = a % b;
a = temp;
}
return b;
}
}