0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-08 16:18:46 +00:00

D1 - Divan and Kostomuksha (easy version)

https://codeforces.com/contest/1614/submission/137046622
This commit is contained in:
Baoshuo Ren 2021-11-26 22:34:50 +08:00 committed by Baoshuo Ren
parent 0dad6607f2
commit 02b392f386
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

37
CodeForces/1614/D1/D1.cpp Normal file
View File

@ -0,0 +1,37 @@
#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::endl;
int n;
long long a[100005], cnt[5000005], f[5000005], max, ans;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
max = std::max(max, a[i]);
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j * j <= a[i]; j++) {
if (a[i] % j == 0) {
cnt[j]++;
if (j * j != a[i]) {
cnt[a[i] / j]++;
}
}
}
}
for (int i = 1; i <= max; i++) {
f[i] = cnt[i] * i;
}
for (int i = max; i > 0; i--) {
for (int j = i << 1; j <= max; j += i) {
f[i] = std::max(f[i], f[j] + (cnt[i] - cnt[j]) * i);
}
ans = std::max(ans, f[i]);
}
cout << ans << endl;
return 0;
}