結果

問題 No.2570 最大最大公約数
ユーザー mymelochanmymelochan
提出日時 2023-12-02 16:47:35
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 126 ms / 2,000 ms
コード長 1,099 bytes
コンパイル時間 178 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 66,416 KB
最終ジャッジ日時 2023-12-02 16:47:39
合計ジャッジ時間 3,860 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 111 ms
64,324 KB
testcase_01 AC 115 ms
66,404 KB
testcase_02 AC 126 ms
66,408 KB
testcase_03 AC 88 ms
66,404 KB
testcase_04 AC 105 ms
64,324 KB
testcase_05 AC 110 ms
66,396 KB
testcase_06 AC 112 ms
66,404 KB
testcase_07 AC 109 ms
64,324 KB
testcase_08 AC 111 ms
66,404 KB
testcase_09 AC 110 ms
66,404 KB
testcase_10 AC 107 ms
64,324 KB
testcase_11 AC 106 ms
64,324 KB
testcase_12 AC 115 ms
66,404 KB
testcase_13 AC 110 ms
64,324 KB
testcase_14 AC 103 ms
66,396 KB
testcase_15 AC 125 ms
64,324 KB
testcase_16 AC 119 ms
64,324 KB
testcase_17 AC 44 ms
55,600 KB
testcase_18 AC 59 ms
66,416 KB
testcase_19 AC 55 ms
64,296 KB
testcase_20 AC 51 ms
61,668 KB
testcase_21 AC 56 ms
64,296 KB
testcase_22 AC 55 ms
64,168 KB
testcase_23 AC 52 ms
61,668 KB
testcase_24 AC 57 ms
64,316 KB
testcase_25 AC 58 ms
64,296 KB
testcase_26 AC 55 ms
64,168 KB
testcase_27 AC 54 ms
64,340 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#############################################################

import sys
sys.setrecursionlimit(10**7)

from heapq import heappop,heappush
from collections import deque,defaultdict,Counter
from bisect import bisect_left, bisect_right
from itertools import product,combinations,permutations
from math import sin,cos
#from math import isqrt #DO NOT USE PyPy

ipt = sys.stdin.readline
iin = lambda :int(ipt())
lmin = lambda :list(map(int,ipt().split()))

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

#############################################################

N,K = lmin()
A = lmin()

ans = 0
for i in range(N):
    D = make_divisors(A[i])
    for d in D:
        cnt = 0
        for j in range(N):
            if i == j:
                continue
            cnt += min(A[j]%d,(-A[j])%d)
        if cnt <= K:
            ans = max(ans,d)

print(ans)
0