結果

問題 No.1611 Minimum Multiple with Double Divisors
ユーザー persimmon-persimmon
提出日時 2022-04-01 13:32:08
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,089 bytes
コンパイル時間 337 ms
コンパイル使用メモリ 82,664 KB
実行使用メモリ 78,932 KB
最終ジャッジ日時 2024-11-19 04:58:15
合計ジャッジ時間 8,877 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 9 WA * 28
権限があれば一括ダウンロードができます

ソースコード

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,prime):
    arr = []
    temp = n
    for p in prime:
        if temp%p==0:
            cnt=0
            while temp%p==0:
                cnt+=1
                temp //= p
            arr.append([p, cnt])
    if temp!=1:
        arr.append([temp, 1])
    if arr==[]:
        arr.append([n, 1])
    return arr
prime=eratosthenes(32)
prime.sort()
t=int(input())
xx=[int(input()) for _ in range(t)]
inf=float('inf')
for x in xx:
    ary=factorization(x,prime)
    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