結果

問題 No.2570 最大最大公約数
ユーザー ryusukeryusuke
提出日時 2023-12-02 20:07:15
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 417 ms / 2,000 ms
コード長 736 bytes
コンパイル時間 336 ms
コンパイル使用メモリ 11,904 KB
実行使用メモリ 10,240 KB
最終ジャッジ日時 2023-12-02 20:07:23
合計ジャッジ時間 7,773 ms
ジャッジサーバーID
(参考情報)
judge11 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 264 ms
10,112 KB
testcase_01 AC 391 ms
10,112 KB
testcase_02 AC 417 ms
10,112 KB
testcase_03 AC 154 ms
10,112 KB
testcase_04 AC 332 ms
10,240 KB
testcase_05 AC 360 ms
10,240 KB
testcase_06 AC 363 ms
10,240 KB
testcase_07 AC 367 ms
10,240 KB
testcase_08 AC 353 ms
10,240 KB
testcase_09 AC 346 ms
10,240 KB
testcase_10 AC 348 ms
10,240 KB
testcase_11 AC 342 ms
10,240 KB
testcase_12 AC 402 ms
10,240 KB
testcase_13 AC 377 ms
10,240 KB
testcase_14 AC 297 ms
10,240 KB
testcase_15 AC 319 ms
10,240 KB
testcase_16 AC 254 ms
10,112 KB
testcase_17 AC 31 ms
10,112 KB
testcase_18 AC 35 ms
10,112 KB
testcase_19 AC 35 ms
10,112 KB
testcase_20 AC 32 ms
10,112 KB
testcase_21 AC 39 ms
10,112 KB
testcase_22 AC 34 ms
10,112 KB
testcase_23 AC 31 ms
10,112 KB
testcase_24 AC 38 ms
10,112 KB
testcase_25 AC 37 ms
10,112 KB
testcase_26 AC 34 ms
10,112 KB
testcase_27 AC 31 ms
10,112 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# verification-helper: PROBLEM https://yukicoder.me/problems/no/2570

def divisors(n: int) -> list:
    divisor = []
    for i in range(1, int(n**0.5) + 1):
        if n % i == 0:
            divisor.append(i)
            if i != n // i:
                divisor.append(n // i)

    divisor.sort()
    return divisor


def main() -> None:
    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    p = set()
    for i in range(N):
        for j in divisors(A[i]):
            p.add(j)

    ans = []
    for x in p:
        cnt = 0
        for i in range(N):
            cnt += min(A[i] % x, x - (A[i] % x))
        if cnt <= K:
            ans.append(x)

    print(max(ans))


if __name__ == "__main__":
    main()
0