https://codeforc.es/problemset/problem/1216/D
greedy:
Find the maximum of the a [i], so as t, i.e., t is assumed that the original x
Then b [i] = ta [i]; b [i] represents the number of each of the missing.
Finally, all seeking a b [i] is the greatest common divisor.
The answer is accumulated b [i] / gcd
1 #include <bits/stdc++.h> 2 using namespace std; 3 #define ll long long 4 int const N = 200000 + 10; 5 int a[N], b[N], n, ta; 6 int gcd(int a, int b) 7 { 8 return b ? gcd(b, a % b) : a; 9 } 10 int main() 11 { 12 scanf("%d", &n); 13 for (int i = 1; i <= n; i++) 14 { 15 scanf("%d", &a[i]); 16 ta = max(ta, a[i]); 17 } 18 for (int i = 1; i <= n; i++) 19 b[i] = ta - a[i]; 20 int g = b[1]; 21 for (int i = 2; i <= n; i++) 22 g = gcd(g, b[i]); 23 ll ans = 0; 24 for (int i = 1; i <= n; i++) 25 ans += b[i] / g; 26 printf("%lld %d\n", ans, g); 27 return 0; 28 }