-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1216D.cpp
More file actions
52 lines (46 loc) · 1.15 KB
/
1216D.cpp
File metadata and controls
52 lines (46 loc) · 1.15 KB
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
#include <bits/stdc++.h>
using namespace std;
vector<long long> divisors(long long x) {
vector<long long> res;
for(long long i = 1; i <= sqrt(x); i++) {
if(x % i == 0) {
res.push_back(i);
if(x / i != i) res.push_back(x/i);
}
}
return res;
}
int main() {
long long n; cin >> n;
vector<long long> v(n, 0);
for(long long i = 0; i < n; i++) {
cin >> v[i];
}
long long mx = *max_element(v.begin(), v.end());
auto it = find_if(v.begin(), v.end(), [&mx](long long elem){ return elem != mx; });
if (it == v.end()) {
cout << 0 << " " << 0 << endl;
return 0;
}
long long k = mx - *it;
vector<long long> ds = divisors(k);
sort(ds.rbegin(), ds.rend());
long long y = 0, z = 0;
for(long long d : ds) {
bool ok = true;
long long ty = 0;
for(long long x : v) {
if((mx - x) % d != 0) {
ok = false;
break;
}
ty += (mx - x) / d;
}
if(ok) {
y = ty;
z = d;
break;
}
}
cout << y << " " << z << endl;
}