結果

問題 No.1611 Minimum Multiple with Double Divisors
ユーザー persimmon-persimmon
提出日時 2022-04-01 13:25:03
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
TLE  
実行時間 -
コード長 1,105 bytes
コンパイル時間 96 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 32,676 KB
最終ジャッジ日時 2024-11-19 04:39:24
合計ジャッジ時間 69,074 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 8 WA * 10 TLE * 19
権限があれば一括ダウンロードができます

ソースコード

diff #


# 指定した整数以下の素数を列挙。エラトステネスの篩
def eratosthenes(n):
    l0=list(range(2,n+1))
    l1=[1]*(n+1)
    l1[0]=0
    l1[1]=0
    for li in l0:
        if li>int(n**0.5):
            break
        if l1[li]==1:
            k=2
        while k*li<=n:
            l1[k*li]=0
            k+=1
    ret=[i for i,li in enumerate(l1) if li==1]
    return ret

# 素因数分解
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])
    if arr==[]:
        arr.append([n, 1])
    return arr
t=int(input())
xx=[int(input()) for _ in range(t)]
inf=float('inf')
prime=eratosthenes(10**3)
prime.sort()
for x in xx:
    ary=factorization(x)
    ps={p:q for p,q in ary}
    # pow(p,ps[p]+1)
    ans=inf
    for p in prime:
        if p in ps:
            ans=min(ans,x*pow(p,ps[p]+1))
        else:
            ans=min(ans,x*p)
    print(ans)
0