結果

問題 No.2570 最大最大公約数
ユーザー prd_xxxprd_xxx
提出日時 2023-12-02 16:53:09
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 153 ms / 2,000 ms
コード長 525 bytes
コンパイル時間 231 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 100,848 KB
最終ジャッジ日時 2023-12-02 16:53:14
合計ジャッジ時間 3,744 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 90 ms
61,724 KB
testcase_01 AC 98 ms
61,724 KB
testcase_02 AC 106 ms
61,724 KB
testcase_03 AC 72 ms
61,724 KB
testcase_04 AC 111 ms
76,492 KB
testcase_05 AC 129 ms
91,792 KB
testcase_06 AC 140 ms
94,756 KB
testcase_07 AC 99 ms
64,296 KB
testcase_08 AC 98 ms
65,028 KB
testcase_09 AC 144 ms
100,704 KB
testcase_10 AC 153 ms
100,680 KB
testcase_11 AC 143 ms
100,676 KB
testcase_12 AC 148 ms
100,536 KB
testcase_13 AC 145 ms
100,848 KB
testcase_14 AC 101 ms
75,176 KB
testcase_15 AC 99 ms
72,256 KB
testcase_16 AC 92 ms
70,124 KB
testcase_17 AC 38 ms
53,332 KB
testcase_18 AC 46 ms
59,900 KB
testcase_19 AC 43 ms
59,516 KB
testcase_20 AC 45 ms
59,500 KB
testcase_21 AC 45 ms
59,644 KB
testcase_22 AC 44 ms
59,464 KB
testcase_23 AC 43 ms
59,500 KB
testcase_24 AC 52 ms
64,200 KB
testcase_25 AC 49 ms
61,836 KB
testcase_26 AC 43 ms
59,464 KB
testcase_27 AC 43 ms
59,500 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N,K = map(int,input().split())
A = list(map(int,input().split()))

divs = set()
for a in A:
    m = 1
    while m*m <= a:
        if N%m==0:
            divs.add(m)
            divs.add(a//m)
        m += 1

cands = set()
for d in divs:
    for i in range(-K,K+1):
        if d+i > 0:
            cands.add(d+i)

for g in sorted(cands, reverse=True):
    cnt = 0
    for a in A:
        tmp = -a%g
        if a > g:
            tmp = min(tmp, a%g)
        cnt += tmp
        if cnt > K: break
    else:
        exit(print(g))
0