結果

問題 No.1611 Minimum Multiple with Double Divisors
ユーザー gew1fw
提出日時 2025-06-12 16:20:52
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,777 bytes
コンパイル時間 256 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 92,032 KB
最終ジャッジ日時 2025-06-12 16:21:13
合計ジャッジ時間 10,799 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 2
other AC * 1 WA * 10 TLE * 1 -- * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import math

def is_prime(n):
    if n <= 1:
        return False
    elif n <= 3:
        return True
    elif n % 2 == 0:
        return False
    d = n - 1
    s = 0
    while d % 2 == 0:
        d //= 2
        s += 1
    bases = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37]
    for a in bases:
        if a >= n:
            continue
        x = pow(a, d, n)
        if x == 1 or x == n - 1:
            continue
        for _ in range(s - 1):
            x = pow(x, 2, n)
            if x == n - 1:
                break
        else:
            return False
    return True

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

def find_p_min(factors):
    primes = set(factors.keys())
    candidate = 2
    while True:
        if candidate not in primes and is_prime(candidate):
            return candidate
        if candidate == 2:
            candidate += 1
        else:
            candidate += 2

def main():
    input = sys.stdin.read().split()
    T = int(input[0])
    for i in range(1, T + 1):
        X = int(input[i])
        if X == 1:
            print(2)
            continue
        factors = factorize(X)
        primes = factors.keys()
        p_min = find_p_min(factors)
        Y1 = X * p_min
        min_Y = Y1
        for p in primes:
            exponent = factors[p]
            k = p ** (exponent + 1)
            Y_candidate = X * k
            if Y_candidate < min_Y:
                min_Y = Y_candidate
        print(min_Y)

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