結果

問題 No.1581 Multiple Sequence
ユーザー buey_tbuey_t
提出日時 2023-03-31 14:09:21
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 338 ms / 2,000 ms
コード長 3,337 bytes
コンパイル時間 171 ms
コンパイル使用メモリ 81,604 KB
実行使用メモリ 106,184 KB
最終ジャッジ日時 2023-10-24 01:35:44
合計ジャッジ時間 8,624 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 219 ms
104,340 KB
testcase_01 AC 229 ms
104,344 KB
testcase_02 AC 316 ms
105,644 KB
testcase_03 AC 315 ms
105,656 KB
testcase_04 AC 274 ms
105,656 KB
testcase_05 AC 316 ms
105,920 KB
testcase_06 AC 288 ms
105,656 KB
testcase_07 AC 278 ms
105,656 KB
testcase_08 AC 288 ms
105,656 KB
testcase_09 AC 318 ms
105,656 KB
testcase_10 AC 306 ms
105,656 KB
testcase_11 AC 268 ms
105,392 KB
testcase_12 AC 279 ms
105,656 KB
testcase_13 AC 252 ms
105,524 KB
testcase_14 AC 325 ms
105,656 KB
testcase_15 AC 304 ms
105,656 KB
testcase_16 AC 273 ms
105,656 KB
testcase_17 AC 330 ms
106,184 KB
testcase_18 AC 263 ms
105,392 KB
testcase_19 AC 318 ms
105,656 KB
testcase_20 AC 326 ms
105,656 KB
testcase_21 AC 327 ms
105,656 KB
testcase_22 AC 299 ms
105,656 KB
testcase_23 AC 338 ms
106,184 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    from math import sqrt,sin,cos,tan,ceil,radians,floor,gcd,exp,log,log10,log2,factorial,fsum
    from heapq import heapify, heappop, heappush
    from bisect import bisect_left, bisect_right
    from copy import deepcopy
    import copy
    import random
    from collections import deque,Counter,defaultdict
    from itertools import permutations,combinations
    from decimal import Decimal,ROUND_HALF_UP
    #tmp = Decimal(mid).quantize(Decimal('0'), rounding=ROUND_HALF_UP)
    from functools import lru_cache, reduce
    #@lru_cache(maxsize=None)
    from operator import add,sub,mul,xor,and_,or_,itemgetter
    INF = 10**18
    mod1 = 10**9+7
    mod2 = 998244353
    
    #DecimalならPython
    #再帰ならPython!!!!!!!!!!!!!!!!!!!!!!!!!!
    
    class Eratosthenes:
        def __init__(self, n):
            self.isprime = [True]*(n+1)
            self.minfactor = [-1]*(n+1)
            self.isprime[1] = False
            self.minfactor[1] = 1
            for p in range(2, n + 1):
                if self.isprime[p]:
                    self.minfactor[p] = p
                    q = p
                    while q <= n:
                        self.isprime[q] = False
                        q += p
                        
                        if q > n:
                            break
                        
                        if self.minfactor[q] == -1:
                            self.minfactor[q] = p
        
        def factorize(self, n):
            factors = []
            while n > 1:
                p = self.minfactor[n]
                exp = 0
                while self.minfactor[n] == p:
                    n //= p
                    exp += 1
                factors.append((p, exp))
            return factors
        
        def divisors(self, n):
            res = [1]
            pf = self.factorize(n)
            for p in pf:
                s = len(res)
                for i in range(s):
                    v = 1
                    for j in range(p[1]):
                        v *= p[0]
                        res.append(res[i] * v)
            return res
    
    
    
    '''
    大事なのは
    1個め何にするか
    2個目移行どんだけ飛ばすか
    1個めが公約数であるので、まずMを約数分解する
    素因数分解して、2,2*3,2*3*5みたいな
    M-1までは1の組み合わせで行ける
    約数に分解すれば約数*M/約数の数列で行ける
    素因数分解して、1個で構成されているなら、分解できるから、
    2^6なら、{2,2,2,2,2,2},{2,2^5},{2,2,2^4},{2^2,2^4}
    めっちゃあるな
    まずe-1個
    次にe/2して、最小単位をp^2にする
    それでe/2-1個
    ってやってく
    
    漸化式を発見できればよかったんだが
    よい数列から別のよい数列がつくれること
    '''
    
    M = int(input())
    
    er = Eratosthenes(10**6)
    
    dp = [0]*(M+1)
    dp[0] = 1
    
    for i in range(1,M+1):
        for d in er.divisors(i):
            dp[i] += dp[i//d-1]
        dp[i] %= mod1
    
    print(dp[M])
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
if __name__ == '__main__':
    main()
0