結果

問題 No.1611 Minimum Multiple with Double Divisors
ユーザー gew1fw
提出日時 2025-06-12 21:30:26
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,532 bytes
コンパイル時間 328 ms
コンパイル使用メモリ 82,128 KB
実行使用メモリ 195,972 KB
最終ジャッジ日時 2025-06-12 21:31:05
合計ジャッジ時間 9,245 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 2
other WA * 11 TLE * 1 -- * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import math

def factorize(x):
    factors = {}
    while x % 2 == 0:
        factors[2] = factors.get(2, 0) + 1
        x = x // 2
    i = 3
    max_factor = math.sqrt(x)
    while i <= max_factor:
        while x % i == 0:
            factors[i] = factors.get(i, 0) + 1
            x = x // i
            max_factor = math.sqrt(x)
        i += 2
    if x > 1:
        factors[x] = 1
    return factors

def is_prime(n):
    if n < 2:
        return False
    for p in [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37]:
        if n % p == 0:
            return n == p
    max_div = int(math.sqrt(n)) + 1
    for i in range(3, max_div, 2):
        if n % i == 0:
            return False
    return True

def get_smallest_missing_prime(factors):
    candidate = 2
    while True:
        if candidate not in factors:
            if is_prime(candidate):
                return candidate
        candidate += 1

def main():
    input = sys.stdin.read().split()
    T = int(input[0])
    cases = list(map(int, input[1:T+1]))
    for X in cases:
        if X == 0:
            print(0)
            continue
        if X == 1:
            print(2)
            continue
        factors = factorize(X)
        x_factors = factors.keys()
        
        p_min = get_smallest_missing_prime(x_factors)
        Y1 = X * p_min
        
        p_min_X = min(x_factors)
        a_min_X = factors[p_min_X]
        Y2 = X * (p_min_X ** (a_min_X + 1))
        
        Y = min(Y1, Y2)
        print(Y)

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