結果
| 問題 | No.3461 Min GCD |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-03-01 00:56:04 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
AC
|
| 実行時間 | 1,458 ms / 2,000 ms |
| コード長 | 1,082 bytes |
| 記録 | |
| コンパイル時間 | 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 |
ソースコード
# 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()