結果
| 問題 |
No.1611 Minimum Multiple with Double Divisors
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 16:45:09 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,832 bytes |
| コンパイル時間 | 365 ms |
| コンパイル使用メモリ | 82,220 KB |
| 実行使用メモリ | 99,348 KB |
| 最終ジャッジ日時 | 2025-06-12 16:45:24 |
| 合計ジャッジ時間 | 8,164 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 2 |
| other | AC * 1 WA * 10 TLE * 1 -- * 25 |
ソースコード
import sys
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 is_prime(n):
if n < 2:
return False
if n % 2 == 0:
return n == 2
max_div = int(n ** 0.5) + 1
for i in range(3, max_div, 2):
if n % i == 0:
return False
return True
def find_min_q(factors):
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293]
for p in primes:
if p not in factors:
return p
next_p = primes[-1] + 2
while True:
if is_prime(next_p) and next_p not in factors:
return next_p
next_p += 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 == 0:
print(0)
continue
factors = factorize(X)
case2_candidates = []
for p, e in factors.items():
if (e + 1) % 2 == 0:
power = e + 1
y_i = X * (p ** power)
case2_candidates.append(y_i)
min_case2 = None
if case2_candidates:
min_case2 = min(case2_candidates)
q = find_min_q(factors)
y_j = X * q
if case2_candidates:
y = min(min_case2, y_j)
else:
y = y_j
print(y)
if __name__ == "__main__":
main()
gew1fw