20250914 baekjoon
This commit is contained in:
parent
726f935151
commit
3a65782372
38
code_study/Baekjoon/c/2485.c
Normal file
38
code_study/Baekjoon/c/2485.c
Normal 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;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user