結果

問題 No.3461 Min GCD
コンテスト
ユーザー LyricalMaestro
提出日時 2026-03-01 00:56:04
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 1,458 ms / 2,000 ms
コード長 1,082 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 227 ms
コンパイル使用メモリ 77,956 KB
実行使用メモリ 326,824 KB
最終ジャッジ日時 2026-03-01 00:56:38
合計ジャッジ時間 10,109 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

# https://yukicoder.me/problems/no/3461

import math

MAX_INT = 10 ** 12



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

    max_a = max(A)
    divisors_map = [[] for _ in range(max_a + 1)]
    for i in range(N):
        a =A[i]
        sqrt_a = int(math.sqrt(a))

        divisors = []
        for p in range(1, sqrt_a + 1):
            if a % p == 0:
                q = a // p
                divisors.append(p)
                if q != p:
                    divisors.append(q)

        for d in divisors:
            divisors_map[d].append(i)

    border = [MAX_INT for _ in range(N)]    
    ans = MAX_INT * N
    for a in reversed(range(1, max_a + 1)):

        for index in divisors_map[a]:
            x = B[index] % a
            x = (a - x) % a
            if border[index] > x:
                old_x = border[index]
                ans += x - old_x
                border[index] = x
        if ans <= K:
            print(a)
            return



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