結果

問題 No.1581 Multiple Sequence
ユーザー FromBooskaFromBooska
提出日時 2023-06-19 14:37:42
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 591 ms / 2,000 ms
コード長 1,154 bytes
コンパイル時間 1,403 ms
コンパイル使用メモリ 86,448 KB
実行使用メモリ 77,572 KB
最終ジャッジ日時 2023-09-09 09:48:44
合計ジャッジ時間 10,763 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,120 KB
testcase_01 AC 73 ms
71,332 KB
testcase_02 AC 475 ms
77,268 KB
testcase_03 AC 519 ms
77,308 KB
testcase_04 AC 180 ms
76,852 KB
testcase_05 AC 542 ms
77,572 KB
testcase_06 AC 261 ms
77,132 KB
testcase_07 AC 172 ms
76,932 KB
testcase_08 AC 213 ms
76,824 KB
testcase_09 AC 490 ms
77,456 KB
testcase_10 AC 328 ms
77,308 KB
testcase_11 AC 122 ms
76,724 KB
testcase_12 AC 225 ms
77,008 KB
testcase_13 AC 85 ms
76,376 KB
testcase_14 AC 523 ms
77,544 KB
testcase_15 AC 380 ms
77,048 KB
testcase_16 AC 134 ms
76,812 KB
testcase_17 AC 579 ms
77,084 KB
testcase_18 AC 113 ms
76,788 KB
testcase_19 AC 453 ms
77,452 KB
testcase_20 AC 476 ms
77,264 KB
testcase_21 AC 513 ms
77,564 KB
testcase_22 AC 304 ms
76,760 KB
testcase_23 AC 591 ms
77,328 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# 1次元dp
# dp[i] 要素合計iで、要素すべてが1以上の整数で、すべてが倍数関係、のパターン数
# dp[1] = 1 for [1]
# dp[2] = 2 for [1, 1] and [2]
# dp[3] = 3 for [1, 1, 1], [1, 2], and [3]
# dp[4] = 5 for [1, 1, 1, 1], [1, 1, 2], [1, 3], [2, 2] and [4]
# dp[5] = 6 for [1, 1, 1, 1, 1], [1, 1, 1, 2], [1, 1, 3], [1, 2, 2], [1, 4], [5]
# 遷移が思いつかなかった
# 公式解説より、数列の第1項は常にiの約数であり、それをjとする
# その数列のすべての要素はjで割り切れるのでjで割ると、第1項は1となり、残りの項の数はdp[i//j-1]となる

def divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

M = int(input())
mod = 10**9+7
dp = [0]*(M+1)
dp[0] = 1 #便宜的に1とする

for i in range(1, M+1):
    divs = divisors(i)
    for d in divs:
        dp[i] += dp[i//d-1]
    dp[i] %= mod

#print(dp)

ans = dp[M]%mod
print(ans)
0