結果

問題 No.1581 Multiple Sequence
ユーザー 👑 KazunKazun
提出日時 2021-07-03 00:05:19
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 392 ms / 2,000 ms
コード長 1,575 bytes
コンパイル時間 424 ms
コンパイル使用メモリ 86,828 KB
実行使用メモリ 79,988 KB
最終ジャッジ日時 2023-09-12 00:25:58
合計ジャッジ時間 7,826 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,596 KB
testcase_01 AC 71 ms
71,352 KB
testcase_02 AC 355 ms
79,584 KB
testcase_03 AC 357 ms
79,764 KB
testcase_04 AC 200 ms
78,748 KB
testcase_05 AC 371 ms
79,920 KB
testcase_06 AC 240 ms
78,872 KB
testcase_07 AC 193 ms
78,692 KB
testcase_08 AC 221 ms
78,876 KB
testcase_09 AC 343 ms
79,672 KB
testcase_10 AC 285 ms
79,200 KB
testcase_11 AC 164 ms
78,528 KB
testcase_12 AC 229 ms
79,060 KB
testcase_13 AC 118 ms
78,124 KB
testcase_14 AC 357 ms
79,772 KB
testcase_15 AC 305 ms
79,320 KB
testcase_16 AC 174 ms
78,496 KB
testcase_17 AC 379 ms
79,988 KB
testcase_18 AC 158 ms
78,424 KB
testcase_19 AC 345 ms
79,548 KB
testcase_20 AC 353 ms
79,612 KB
testcase_21 AC 370 ms
79,868 KB
testcase_22 AC 269 ms
79,176 KB
testcase_23 AC 392 ms
79,868 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def Smallest_Prime_Factor(N):
    """0,1,2,...,Nの最小の素因数のリスト(0,1については1にしている)
    """

    if N==0:
        return [1]

    N=abs(N)
    L=list(range(N+1))
    L[0]=L[1]=1

    x=4
    while x<=N:
        L[x]=2
        x+=2

    x=9
    while x<=N:
        if L[x]==x:
            L[x]=3
        x+=6

    x=5
    Flag=0
    while x*x<=N:
        if L[x]==x:
            y=x*x
            while y<=N:
                if L[y]==y:
                    L[y]=x
                y+=x<<1
        x+=2+2*Flag
        Flag^=1

    return L

def Faster_Prime_Factorization(N,L):
    """

    L:Smallest_Prime_Factors(N)で求めたリスト
    """
    N=abs(N)

    D=[]
    while N>1:
        a=L[N]
        k=0
        while L[N]==a:
            k+=1
            N//=a
        D.append([a,k])
    return D

#素因数分解の結果から, 約数を全て求める.
def Divisors_from_Prime_Factor(P,sorting=False):
    from itertools import product

    def integer_product(t):
        x=1
        for a in t:x*=a
        return x

    A=[]
    for p,e in P:
        B=[1]
        x=1
        for _ in range(e):
            x*=p
            B.append(x)
        A.append(B)
    X=[integer_product(t) for t in product(*A)]

    if sorting: X.sort()
    return X
#==================================================
M=int(input())
Mod=10**9+7

DP=[0]*(M+1)
DP[0]=1

L=Smallest_Prime_Factor(M)

for i in range(1,M+1):
    for j in Divisors_from_Prime_Factor(Faster_Prime_Factorization(i,L)):
        DP[i]+=DP[i//j-1]
    DP[i]%=Mod

print(DP[M])
0