题目描述:
思路 : 考虑这个问题: 式: x! + y! + k!,(x < y < k) 的最大公因数是否一定是x!? 假设不是x!,而是y!,则原式 = y!
×
\times
×(
x
!
y
!
\frac {x!~}{y!}
y!x! + 1 +
k
!
y
!
\frac {k!}{y!}
y!k!)。易得,
x
!
y
!
\frac {x!~}{y!}
y!x! 为小数,1 +
k
!
y
!
\frac {k!}{y!}
y!k!为整数,所以y!一定不是最大公因数。最大公因数只能为x!。
继续观察样例: 2!+ 2!+ 2!的最大公因数为 3!,显然(x + 1)
×
\times
× x! = (x + 1) ! 。所以我们只需要不断更新最小的x!,最后无法变得更大的x!,就是答案。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
//#define int long long
#define ios ios::sync_with_stdio(false); cin.tie(0);cout.tie(0)
const int N = 1e5+5;
int n, a[N];
void solve(){
cin >> n;
map<int , int> mp, mp1;
for(int i = 1; i <= n; i++) cin >> a[i], mp[a[i]]++;
int ans = 0;
for(auto [x, y] : mp){
if(y % (x + 1) == 0){
mp[x + 1] += y /(x + 1);
ans = x + 1;
mp[x] = 0;
}else{
ans = x;
break;
}
}
cout << ans;
}
signed main(){
ios; int _;
_ = 1; //cin >> _;
while(_--){
solve();
}
return 0;
}