結果

問題 No.2244 Integer Complete
ユーザー lam6er
提出日時 2025-04-16 16:45:33
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,236 bytes
コンパイル時間 247 ms
コンパイル使用メモリ 81,352 KB
実行使用メモリ 93,432 KB
最終ジャッジ日時 2025-04-16 16:46:43
合計ジャッジ時間 4,862 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19 TLE * 1 -- * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

import bisect
import math

def main():
    import sys
    input = sys.stdin.read().split()
    ptr = 0
    N, M = int(input[ptr]), int(input[ptr+1])
    ptr += 2
    A = list(map(int, input[ptr:ptr+N]))
    ptr += N
    B = list(map(int, input[ptr:ptr+M]))
    ptr += M

    A_sorted = A
    B_sorted = B

    def is_in_A(x):
        s = math.isqrt(x)
        idx = bisect.bisect_left(A_sorted, s)
        if idx < len(A_sorted) and A_sorted[idx] == s:
            return s**2 <= x <= (s + 1)**2 - 1
        return False

    def is_in_B(x):
        s = math.isqrt(x)
        idx = bisect.bisect_left(B_sorted, s)
        if idx < len(B_sorted) and B_sorted[idx] == s:
            return s**2 <= x <= (s + 1)**2 - 1
        return False

    k = 1
    while True:
        divisors = set()
        for i in range(1, int(math.isqrt(k)) + 1):
            if k % i == 0:
                divisors.add(i)
                divisors.add(k // i)
        found = False
        for d in divisors:
            if (is_in_A(d) and is_in_B(k // d)) or (is_in_B(d) and is_in_A(k // d)):
                found = True
                break
        if not found:
            print(k)
            return
        k += 1

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