智障了,居然贪心做了暴力枚举记录[1,100]每对的减少最大值,记录每个数字个数枚举最小值
#include<bits/stdc++.h>
using namespace std;
#define fst first
#define sec second
#define sci(num) scanf("%d",&num)
#define scl(num) scanf("%lld",&num)
#define mem(a,b) memset(a,b,sizeof a)
#define cpy(a,b) memcopy(a,b,sizeof b)
typedef long long LL;
typedef pair<int,int> P;
const int MAX_N = 5e4 + 100;
int ps[110][110];
int del[110][110];
bool mark[110];
int nums[MAX_N];
int main() {
ios::sync_with_stdio(false); cin.tie(0);
mem(ps,0);
ps[1][++ps[1][0]] = 1;
ps[1][++ps[1][0]] = 1;
for (int i = 2;i <= 100;i++) {
for (int j = 1;j * j <= i;j++) {
if (i % j == 0) ps[i][++ps[i][0]] = j,ps[i][++ps[i][0]] = i / j;
}
sort(ps[i] + 1,ps[i]+1 + ps[i][0]);
}
mem(del,0x3f3f3f3f);
for (int i = 1;i <= 100;i++) {
for (int j = i+1;j <= 100;j++) {
for (int k = 1;k <= ps[j][0];k++) {
del[i][j] = min(- i - j + i * ps[j][k] + j / ps[j][k],del[i][j]);
}
}
}
mem(mark,0);
int N;
cin >> N;
int sum = 0;
for (int i= 1;i <= N;i++) {
int num;
cin >> num;
mark[num] = true;
sum += num;
}
int ans = sum;
for (int i = 1;i <= 100;i++) {
if (!mark[i]) continue;
for (int j = i+1;j <= 100;j++) {
if (!mark[j]) continue;
ans = min(ans,sum + del[i][j]);
}
}
cout << ans << endl;
return 0;
}