Codeforces1216D Swords

原题链接:Codeforces1216D

$\gcd$

猜测:剩余最多的一种🗡的是没有被偷过的,由于每个人只能偷一种🗡且数量相同,只要求各类被偷🗡数量的$ gcd $,则人数最少。

 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
#include <iostream>
#include <algorithm>
 
using namespace std;
 
typedef long long LL;
 
const int N = 200020;
 
int n;
LL a[N], s[N];
 
LL gcd(LL a, LL b) {
    return !b ? a : gcd(b, a % b);
}
 
int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        s[i] = s[i - 1] + a[i];
    }
    sort(a + 1, a + n + 1);
    for (int i = 1; i <= n - 1; i++) a[i] = a[n] - a[i];
    LL z = 0;
    for (int i = 1; i <= n - 1; i++) z = gcd(z, a[i]);
    LL y = (n * a[n] - s[n]) / z;
    cout << y << " " << z << endl;
    return 0;
}
updatedupdated2020-05-192020-05-19
加载评论
点击刷新