結果

問題 No.3461 Min GCD
コンテスト
ユーザー 👑 loop0919
提出日時 2026-02-28 15:23:56
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
TLE  
実行時間 -
コード長 1,803 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 268 ms
コンパイル使用メモリ 78,168 KB
実行使用メモリ 493,740 KB
最終ジャッジ日時 2026-02-28 15:24:10
合計ジャッジ時間 11,938 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 18 TLE * 1 -- * 2
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import math
import sys
from itertools import accumulate

input = sys.stdin.readline


class fenwick_tree:
    n = 1
    data = [0 for i in range(n)]

    def __init__(self, N):
        self.n = N
        self.data = [0 for i in range(N)]

    def add(self, p, x):
        assert 0 <= p < self.n, "0<=p<n,p={0},n={1}".format(p, self.n)
        p += 1
        while p <= self.n:
            self.data[p - 1] += x
            p += p & -p

    def sum(self, l, r):
        assert 0 <= l and l <= r and r <= self.n, "0<=l<=r<=n,l={0},r={1},n={2}".format(
            l, r, self.n
        )
        return self.sum0(r) - self.sum0(l)

    def sum0(self, r):
        s = 0
        while r > 0:
            s += self.data[r - 1]
            r -= r & -r
        return s


LIMIT = 10**5 + 10
INF = 10**12


def factorize(n):
    factorized = []
    for i in range(1, math.isqrt(n) + 1):
        if n % i == 0:
            factorized.append(i)
            factorized.append(n // i)

    if math.isqrt(n) ** 2 == n:
        factorized.pop()

    return factorized


N, K = [int(s) for s in input().split()]
A = [int(s) for s in input().split()]
B = [int(s) for s in input().split()]

need_op = [dict() for _ in range(N)]

for i, (a, b) in enumerate(zip(A, B)):
    for fac in factorize(a):
        need_op[i][fac] = (fac - b) % fac

    min_cnt = INF

    for key in sorted(need_op[i], reverse=True):
        min_cnt = min(need_op[i][key], min_cnt)
        need_op[i][key] = min_cnt

keys = [list(sorted(need_op[i])) for i in range(N)]

imos = [0] * LIMIT
for i in range(N):
    for curr, to in zip(keys[i], keys[i][1:]):
        imos[curr] += need_op[i][to]
        imos[to] -= need_op[i][to]

    imos[keys[i][-1]] += INF

imos = [0] + list(accumulate(imos))

print(max(i for i in range(LIMIT) if imos[i] <= K))
0