From 1aee9acbc968230158c7b77246d5fe3f35b9749c Mon Sep 17 00:00:00 2001 From: Baoshuo Ren Date: Thu, 10 Feb 2022 01:31:54 +0800 Subject: [PATCH] =?UTF-8?q?#181.=20Alice&=E6=97=B6=E9=97=B4=E9=9A=A7?= =?UTF-8?q?=E9=81=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://sjzezoj.com/submission/48560 --- S2OJ/181/181.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 S2OJ/181/181.cpp diff --git a/S2OJ/181/181.cpp b/S2OJ/181/181.cpp new file mode 100644 index 00000000..9626e4e1 --- /dev/null +++ b/S2OJ/181/181.cpp @@ -0,0 +1,27 @@ +#include +#include + +using std::cin; +using std::cout; +#define endl '\n' + +const int N = 200005; + +int n, a[N], ans; + +int main() { + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> a[i]; + } + std::sort(a + 1, a + 1 + n); + n = std::unique(a + 1, a + 1 + n) - a - 1; + a[n + 1] = std::numeric_limits::max(); + for (int i = 1; i <= n; i++) { + for (int j = 2; (j - 1) * a[i] <= a[n]; j++) { + ans = std::max(ans, *(std::lower_bound(a + 1, a + 1 + n + 1, j * a[i]) - 1) % a[i]); + } + } + cout << ans << endl; + return 0; +}