20250914 baekjoon

This commit is contained in:
songyc macbook 2025-09-14 21:20:51 +09:00
parent 726f935151
commit 3a65782372

View File

@ -0,0 +1,38 @@
#include <stdio.h>
#include <stdlib.h>
int GCD(int a, int b);
int main() {
int N;
scanf("%d",&N);
int* tree = (int*)malloc(sizeof(int)*N);
for(int i=0; i<N; i++) scanf("%d", &tree[i]);
int* diff = (int*)malloc(sizeof(int)*(N-1));
for(int i=0; i<N-1; i++) diff[i] = tree[i+1] - tree[i];
int gcd = diff[0];
for(int i=1; i<N-1; i++) gcd = GCD(diff[i], gcd);
int result = 0;
for(int i=0; i<N-1; i++) {
result += diff[i]/gcd - 1;
}
printf("%d\n", result);
free(tree);
free(diff);
return 0;
}
int GCD(int a, int b) {
while(b!=0) {
int r = a%b;
a = b;
b = r;
}
return a;
}