結果

問題 No.1611 Minimum Multiple with Double Divisors
ユーザー persimmon-persimmon
提出日時 2022-04-01 13:25:47
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,105 bytes
コンパイル時間 378 ms
コンパイル使用メモリ 82,428 KB
実行使用メモリ 144,216 KB
最終ジャッジ日時 2024-11-19 04:40:53
合計ジャッジ時間 61,725 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 8 WA * 11 TLE * 18
権限があれば一括ダウンロードができます

ソースコード

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