結果
| 問題 | No.2570 最大最大公約数 | 
| コンテスト | |
| ユーザー |  titia | 
| 提出日時 | 2023-12-23 00:05:13 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 975 ms / 2,000 ms | 
| コード長 | 677 bytes | 
| コンパイル時間 | 294 ms | 
| コンパイル使用メモリ | 82,384 KB | 
| 実行使用メモリ | 77,560 KB | 
| 最終ジャッジ日時 | 2024-11-13 17:17:48 | 
| 合計ジャッジ時間 | 6,857 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | AC * 28 | 
ソースコード
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)
        
    
            
            
            
        