-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path02981_Euclidean-algorithm.cpp
More file actions
60 lines (50 loc) · 991 Bytes
/
02981_Euclidean-algorithm.cpp
File metadata and controls
60 lines (50 loc) · 991 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int A, B, C;
int gcd(int a, int b)
{
int u = max(a, b);
int d = min(a, b);
a = u;
b = d;
while (b > 0)
{
int temp = a;
a = b;
b = temp % b;
}
return a;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
int N;
int arr[100];
cin >> N;
for (int i = 0; i < N; i++) cin >> arr[i];
sort(arr, arr + N);
int temp = arr[1] - arr[0];
for (int i = 2; i < N; i++)
{
temp = gcd(temp, arr[i] - arr[i - 1]);
}
vector<int> ans;
ans.push_back(temp);
for (int i = 2; i * i <= temp; i++)
{
if (temp % i == 0)
{
ans.push_back(i);
if (i != temp / i)
ans.push_back(temp / i);
}
}
sort(ans.begin(), ans.end());
for (int i = 0; i < ans.size(); i++)
cout << ans[i] << ' ';
return 0;
}