about summary refs log tree commit diff
path: root/codechef/maxrem.py
blob: 30087c7ffe3e8f954f575ddaf9622f6289169e69 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/usr/bin/env python3
from bisect import bisect   # bisect takes no key argument. What a dick.

input()
a = [-int(i) for i in input().split()]
a.sort()

res = 0
for i in a:
    if i > res: break
    for j in range(i, a[0] + i, i):
        idx = bisect(a, j)
        try:
            tmp = a[idx] % i
        except IndexError:
            continue
        if tmp < res: res = tmp
        if res == i + 1: break

print(-res)