結果

問題 No.2244 Integer Complete
ユーザー lam6er
提出日時 2025-04-16 00:58:48
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,244 bytes
コンパイル時間 426 ms
コンパイル使用メモリ 81,832 KB
実行使用メモリ 72,132 KB
最終ジャッジ日時 2025-04-16 00:59:52
合計ジャッジ時間 5,400 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19 TLE * 1 -- * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

import bisect
import math

def main():
    n, m = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    
    A.sort()
    B.sort()
    
    a_min = A[0]
    b_min = B[0]
    if (a_min ** 2) * (b_min ** 2) > 1:
        print(1)
        return
    
    def is_in_A(x):
        s = int(math.isqrt(x))
        if s * s > x:
            s -= 1
        idx = bisect.bisect_left(A, s)
        return idx < len(A) and A[idx] == s and (s ** 2 <= x < (s + 1) ** 2)
    
    def is_in_B(y):
        t = int(math.isqrt(y))
        if t * t > y:
            t -= 1
        idx = bisect.bisect_left(B, t)
        return idx < len(B) and B[idx] == t and (t ** 2 <= y < (t + 1) ** 2)
    
    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)
        possible = False
        for x in divisors:
            if is_in_A(x):
                y = k // x
                if is_in_B(y):
                    possible = True
                    break
        if not possible:
            print(k)
            return
        k += 1

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