문제
https://www.acmicpc.net/problem/2485
코드
import java.util.*;
import java.io.*;
class Main {
public static void main(String args[]) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
int arr [] = new int [n];
for(int i=0;i<n;i++) {
arr[i] = Integer.parseInt(br.readLine());
}
int interval = 0;
for(int i=1;i<n;i++) {
interval = gcd(arr[i]-arr[i-1], interval);
}
int answer = 0;
for(int i=1;i<n;i++) {
answer += (arr[i] - arr[i-1])/interval - 1;
}
System.out.print(answer);
}
static int gcd(int a, int b) {
if(b == 0) return a;
return gcd(b, a%b);
}
}