結果
問題 |
No.1581 Multiple Sequence
|
ユーザー |
![]() |
提出日時 | 2021-07-03 00:32:24 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 409 ms / 2,000 ms |
コード長 | 2,310 bytes |
コンパイル時間 | 142 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 67,968 KB |
最終ジャッジ日時 | 2024-06-29 13:58:50 |
合計ジャッジ時間 | 6,281 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 |
ソースコード
""" 和と最後の数だけでdpできる。 dp[last][rem] = 通り数 sumは同じだけ増えるし、調和級数なのでそこそこ早い だめでした dp[x] = xの崩し方 """ """ from sys import stdin from collections import deque for M in range(1,50): mod = 10**9+7 q = deque() ans = {} ans[(1,M)] = 1 q.append( (1,M) ) while q: last,rem = q.popleft() for nex in range(last,rem+1,last): tup = (nex,rem-nex) if tup not in ans: ans[tup] = 0 q.append(tup) ans[tup] += ans[(last,rem)] ans[tup] %= mod #print (len(ans)) pans = 0 for tup in ans: if tup[1] == 0: pans += ans[tup] print (M,pans % mod) """ """ 初項を持ってdp? 確かに初項を考えると、それ以降その倍数しか取れない 初項は、Mの約数であることがわかる 上のdpで初項をMの約数で限れば? 待てよ… remはnexの倍数である必要がある """ """ from sys import stdin from collections import deque mod = 10**9+7 M = int(input()) q = deque() ans = {} ans[(1,M)] = 1 q.append( (1,M) ) while q: last,rem = q.popleft() for nex in range(last,rem+1,last): if (rem - nex) % nex == 0: tup = (nex,rem-nex) if tup not in ans: ans[tup] = 0 q.append(tup) ans[tup] += ans[(last,rem)] ans[tup] %= mod print (len(ans)) pans = 0 for tup in ans: if tup[1] == 0: pans += ans[tup] print (pans % mod) """ """ 初項で場合分けたとしよう。 初項はMの約数である。 初項が1の時は、 M-1 を後ろで分けることになる。 なので、その分け方は M/a[0] の場合と等しい。 """ from sys import stdin M = int(stdin.readline()) mod = 10**9+7 ans = [0] * (M+1) ans[1] = 1 for m in range(2,M+1): nans = 1 for fi in range(1,m): if fi**2 > m: break if m % fi == 0: x = fi if (m-x) % x == 0: nans += ans[(m-x)//x] x = m // fi if x != fi and (m-x) % x == 0: nans += ans[(m-x)//x] nans %= mod ans[m] = nans print (ans[-1])