結果
| 問題 | No.3461 Min GCD |
| コンテスト | |
| ユーザー |
koheijkt
|
| 提出日時 | 2026-02-28 16:14:33 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,392 bytes |
| 記録 | |
| コンパイル時間 | 440 ms |
| コンパイル使用メモリ | 77,968 KB |
| 実行使用メモリ | 203,368 KB |
| 最終ジャッジ日時 | 2026-02-28 16:14:50 |
| 合計ジャッジ時間 | 13,353 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 20 TLE * 1 |
ソースコード
import sys, math
sys.setrecursionlimit(10**8)
sys.set_int_max_str_digits(0)
INF = 1e18
MOD = 998244353
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict, Counter
from itertools import product, combinations, permutations, groupby, accumulate
from heapq import heapify, heappop, heappush
input = sys.stdin.readline
def I(): return input().rstrip()
def II(): return int(input().rstrip())
def IS(): return input().rstrip().split()
def MII(): return map(int, input().rstrip().split())
def LI(): return list(input().rstrip())
def TII(): return tuple(map(int, input().rstrip().split()))
def LII(): return list(map(int, input().rstrip().split()))
def LSI(): return list(map(str, input().rstrip().split()))
def GMI(): return list(map(lambda x: int(x) - 1, input().rstrip().split()))
def kiriage(a, b): return (a+b-1)//b
def main():
N, K = MII()
A = LII()
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]
A_divs = []
for a in A:
A_divs.append(make_divisors(a)[::-1])
B = LII()
def solve(m): # 全ペアの GCD を m以上にできますか?
if m == 1:
return True
total_cnt = 0
for i in range(N):
b = B[i]
cnt = K + 1
# a の約数を大きいものから見る
for div in A_divs[i]:
if div == 1:
break
if div < m:
break
# B[i] を div の約数になるまでいくらコストが必要か?
cost = b%div
if cost != 0:
cost = div - cost
# 最小か?
if cost < cnt:
cnt = cost
total_cnt += cnt
return total_cnt <= K
ok = 1
ng = max(A) + 1
for i in range(10):
if solve(ng - i):
exit(print(ng - i))
while abs(ok - ng) != 1:
mid = (ok + ng)//2
if solve(mid):
ok = mid
else:
ng = mid
print(ok)
if __name__ == "__main__":
main()
koheijkt