Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const int N = 2000 * 1000 + 3000;
- int n;
- int a[N];
- inline bool read() {
- n = nextInt();
- forn(i, n) {
- a[i] = nextInt();
- }
- return true;
- }
- int cnt[N];
- int curVal;
- inline int getsum(int l, int r) {
- if (l > r) return 0;
- if (r >= N) {
- r = N - 1;
- }
- int res = cnt[r];
- if (l > 0) res -= cnt[l - 1];
- return res;
- }
- inline bool f(int mid) {
- for(int i = curVal; i < N / 2; i += curVal) {
- int curpos = i + mid;
- if (getsum(curpos, i + curVal - 1) > 0)
- return true;
- }
- return false;
- }
- inline void solve() {
- forn(i, n) {
- cnt[a[i]] ++;
- }
- forn(i, N) {
- if (i > 0) {
- cnt[i] += cnt[i - 1];
- }
- }
- sort(a, a + n);
- n = int(unique(a, a + n) - a);
- int ans = 0;
- forn(i, n) {
- curVal = a[i];
- int l = 0;
- int r = a[i];
- while (r - l > 1) {
- int mid = (r + l) >> 1;
- if (f(mid)) {
- l = mid;
- } else {
- r = mid;
- }
- }
- ans = max(ans, l);
- }
- cout << ans << endl;
- }
- int main()
- {
- #ifdef gridnevvvit
- freopen("input.txt", "rt", stdin);
- freopen("output.txt", "wt", stdout);
- #endif
- //srand(time(NULL));
- cout << setprecision(10) << fixed;
- cerr << setprecision(5) << fixed;
- assert(read());
- solve();
- #ifdef gridnevvvit
- cerr << "===Time: " << clock() << "===" << endl;
- #endif
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement