From 02b392f3861ee877bfc003c35f8503d87831aaa3 Mon Sep 17 00:00:00 2001 From: Ren Baoshuo Date: Fri, 26 Nov 2021 22:34:50 +0800 Subject: [PATCH] D1 - Divan and Kostomuksha (easy version) https://codeforces.com/contest/1614/submission/137046622 --- CodeForces/1614/D1/D1.cpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 CodeForces/1614/D1/D1.cpp diff --git a/CodeForces/1614/D1/D1.cpp b/CodeForces/1614/D1/D1.cpp new file mode 100644 index 00000000..9fb2a93e --- /dev/null +++ b/CodeForces/1614/D1/D1.cpp @@ -0,0 +1,37 @@ +#include + +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; +}