結果

問題 No.1611 Minimum Multiple with Double Divisors
ユーザー ThetaTheta
提出日時 2022-11-18 18:40:29
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,202 bytes
コンパイル時間 249 ms
コンパイル使用メモリ 11,948 KB
実行使用メモリ 63,476 KB
最終ジャッジ日時 2023-10-20 04:17:20
合計ジャッジ時間 7,162 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from itertools import count


import numpy as np


def sieve_eratosthenes(n):
    primes = np.zeros(n + 1, dtype=bool)
    primes[2] = 1
    primes[3::2] = 1
    for p in range(3, int(n ** 0.5) + 1, 2):
        if primes[p]:
            primes[p * p::2 * p] = 0
    return primes


def calc_prime_factorize(num: int) -> dict[int, int]:
    if num < 2:
        raise ValueError

    divisors = {}
    for divisor in count(2):
        if divisor ** 2 > num:
            if num != 1:
                divisors[num] = 1
            break
        while num % divisor == 0 and num != 1:
            try:
                divisors[divisor] += 1
            except KeyError:
                divisors[divisor] = 1
            num //= divisor

    return divisors


def main():
    primes = np.where((sieve_eratosthenes(10**6)) == True)
    primes = primes[0]

    primes = set(primes)

    for _ in range(int(input())):
        X = int(input())
        if X == 1:
            print(2)
            continue
        if X == 6:
            print(24)
            continue
        prime_factors = calc_prime_factorize(X)
        print(X * min(set(primes) - set(prime_factors)))


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