File tree Expand file tree Collapse file tree 1 file changed +11
-11
lines changed
solution/2300-2399/2338.Count the Number of Ideal Arrays Expand file tree Collapse file tree 1 file changed +11
-11
lines changed Original file line number Diff line number Diff line change 11class Solution :
22 def idealArrays (self , n : int , maxValue : int ) -> int :
3- @cache
4- def dfs (i , cnt ):
5- res = c [- 1 ][cnt - 1 ]
6- if cnt < n :
7- k = 2
8- while k * i <= maxValue :
9- res = (res + dfs (k * i , cnt + 1 )) % mod
10- k += 1
11- return res
12-
133 c = [[0 ] * 16 for _ in range (n )]
144 mod = 10 ** 9 + 7
155 for i in range (n ):
166 for j in range (min (16 , i + 1 )):
177 c [i ][j ] = 1 if j == 0 else (c [i - 1 ][j ] + c [i - 1 ][j - 1 ]) % mod
8+ f = [[0 ] * 16 for _ in range (maxValue + 1 )]
9+ for i in range (1 , maxValue + 1 ):
10+ f [i ][1 ] = 1
11+ for j in range (1 , 15 ):
12+ for i in range (1 , maxValue + 1 ):
13+ k = 2
14+ while k * i <= maxValue :
15+ f [k * i ][j + 1 ] = (f [k * i ][j + 1 ] + f [i ][j ]) % mod
16+ k += 1
1817 ans = 0
1918 for i in range (1 , maxValue + 1 ):
20- ans = (ans + dfs (i , 1 )) % mod
19+ for j in range (1 , 16 ):
20+ ans = (ans + f [i ][j ] * c [- 1 ][j - 1 ]) % mod
2121 return ans
You can’t perform that action at this time.
0 commit comments