Is the application of a screening method.
# Include <iostream> # include <cstdio> # include <cstdlib> # include <cstring> # include <string> # include <cmath> # include <map> # include <set> # include <vector> # include <algorithm> # include <stack> # include <queue> # include <cctype> # include <sstream> using namespace std; # define pii pair <int, int> # define LL long intconst int eps = 1e-8; const int INF = 1000000000; const int maxn = 200009; int n, a [maxn], ans =-1; int main () {// freopen ("in9.txt", "r", stdin); // freopen ("out.txt", "w", stdout ); scanf ("% d", & n); for (int I = 0; I <n; I ++) {scanf ("% d ", & a [I]) ;}if (n = 1) {printf ("0 \ n"); return 0 ;}sort (a, a + n ); for (int I = 0; I <n-1; I ++) {if (I & a [I] = a [i-1]) continue; for (int t = a [I] * 2; t <= a [n-1]; t + = a [I]) {int p = lower_bound (a, a + n, t)-a; ans = max (ans, a [P-1] % a [I]);} ans = max (ans, a [n-1] % a [I]);} printf ("% d \ n", ans); // fclose (stdin); // fclose (stdout ); return 0 ;}
Codeforces Round #276 (Div. 2) D-Maximum Value (screening method)