T-coding
백준 1684 같은 나머지 / C++ 본문
728x90
728x90

더보기
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int gcd(int x, int y) {
while (y) {
int t = x % y;
x = y;
y = t;
}
return x;
}
int main() {
ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int n; cin >> n;
vector<int>arr(n);
for (int i = 0; i < n; i++)
cin >> arr[i];
sort(arr.begin(), arr.end());
vector<int>tmp;
for (int i = 1; i < n; i++)
tmp.push_back(arr[i] - arr[i - 1]);
int res = tmp[0];
for (int i = 1; i < tmp.size(); i++)
res = gcd(res, tmp[i]);
cout << res;
return 0;
}
728x90
300x250
'Baekjoon' 카테고리의 다른 글
백준 4659 비밀번호 발음하기 / Python (0) | 2023.03.16 |
---|---|
백준 1107 리모컨 / C++ (0) | 2022.11.30 |
백준 1188 음식 평론가 / C++ (0) | 2022.11.30 |
백준 1662 압축 / C++ (0) | 2022.11.30 |
백준 1753 최단경로 / C++ (0) | 2022.11.30 |