結果
| 問題 |
No.1611 Minimum Multiple with Double Divisors
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-04-16 01:13:59 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,762 bytes |
| コンパイル時間 | 386 ms |
| コンパイル使用メモリ | 82,088 KB |
| 実行使用メモリ | 106,364 KB |
| 最終ジャッジ日時 | 2025-04-16 01:15:48 |
| 合計ジャッジ時間 | 24,254 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 9 WA * 20 TLE * 8 |
ソースコード
import sys
import random
from math import gcd
from collections import defaultdict
def input():
return sys.stdin.read()
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
d = n - 1
s = 0
while d % 2 == 0:
d //= 2
s += 1
for a in [2, 325, 9375, 28178, 450775, 9780504, 1795265022]:
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 pollards_rho(n):
if n % 2 == 0:
return 2
if n % 3 == 0:
return 3
if n % 5 == 0:
return 5
while True:
c = random.randint(1, n-1)
f = lambda x: (pow(x, 2, n) + c) % n
x, y, d = 2, 2, 1
while d == 1:
x = f(x)
y = f(f(y))
d = gcd(abs(x - y), n)
if d != n:
return d
def factor(n):
factors = []
def _factor(n):
if n == 1:
return
if is_prime(n):
factors.append(n)
return
d = pollards_rho(n)
_factor(d)
_factor(n // d)
_factor(n)
return sorted(factors)
def get_prime_exponents(factors):
counts = defaultdict(int)
for p in factors:
counts[p] += 1
return counts
def find_s(primes_set):
for p in [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]:
if p not in primes_set:
return p
candidate = 101
while True:
if candidate > 10**6:
break
if is_prime(candidate) and candidate not in primes_set:
return candidate
candidate += 2
candidate = 2
while True:
if candidate not in primes_set:
if is_prime(candidate):
return candidate
candidate += 1
def solve():
data = input().split()
T = int(data[0])
cases = list(map(int, data[1:T+1]))
for X in cases:
if X == 1:
print(2)
continue
factors = factor(X)
prime_exponents = get_prime_exponents(factors)
primes_set = set(prime_exponents.keys())
s = find_s(primes_set)
Y_a = X * s
min_power = None
for p in prime_exponents:
exponent = prime_exponents[p]
current = p ** (exponent + 1)
if min_power is None or current < min_power:
min_power = current
Y_b = X * min_power
print(min(Y_a, Y_b))
if __name__ == "__main__":
solve()
lam6er