結果

問題 No.2570 最大最大公約数
ユーザー titiatitia
提出日時 2023-12-23 00:05:13
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 230 ms / 2,000 ms
コード長 677 bytes
コンパイル時間 151 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 76,824 KB
最終ジャッジ日時 2023-12-23 00:05:19
合計ジャッジ時間 4,946 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 173 ms
74,684 KB
testcase_01 AC 197 ms
76,704 KB
testcase_02 AC 230 ms
76,700 KB
testcase_03 AC 136 ms
76,724 KB
testcase_04 AC 121 ms
71,064 KB
testcase_05 AC 180 ms
74,144 KB
testcase_06 AC 197 ms
74,524 KB
testcase_07 AC 56 ms
63,800 KB
testcase_08 AC 67 ms
66,012 KB
testcase_09 AC 221 ms
76,708 KB
testcase_10 AC 222 ms
76,704 KB
testcase_11 AC 223 ms
76,708 KB
testcase_12 AC 224 ms
76,700 KB
testcase_13 AC 222 ms
76,704 KB
testcase_14 AC 172 ms
76,824 KB
testcase_15 AC 160 ms
73,116 KB
testcase_16 AC 114 ms
71,048 KB
testcase_17 AC 44 ms
55,732 KB
testcase_18 AC 51 ms
63,788 KB
testcase_19 AC 43 ms
55,732 KB
testcase_20 AC 51 ms
63,788 KB
testcase_21 AC 50 ms
63,788 KB
testcase_22 AC 53 ms
63,788 KB
testcase_23 AC 50 ms
63,788 KB
testcase_24 AC 61 ms
68,724 KB
testcase_25 AC 61 ms
68,720 KB
testcase_26 AC 53 ms
63,788 KB
testcase_27 AC 54 ms
63,792 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

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

def fact(x):
    xr=round(x**(1/2))+1

    LIST=[]
    for i in range(1,xr+1):
        if x%i==0:
            LIST.append(i)
            LIST.append(x//i)
    return set(LIST)

from functools import lru_cache
@lru_cache(maxsize=None)
def calc(x):
    score=0
    for i in range(N):
        score+=min((x-A[i])%x,(A[i]-x)%x)

    if score<=K:
        return True
    else:
        return False


MAX=max(A)
ANS=0

for i in range(MAX-K,MAX+K+1):
    if i<=0:
        continue
    for f in fact(i):
        if calc(f)==True:
            ANS=max(ANS,f)

print(ANS)
        
    
0