-
Notifications
You must be signed in to change notification settings - Fork 186
/
Copy pathSolution.go
63 lines (56 loc) · 1002 Bytes
/
Solution.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package Solution
const (
MOD int = 1e9 + 7
MAX_N = 10010
MAX_P = 15 // There are up to 15 prime factors
)
var (
c [MAX_N + MAX_P][MAX_P + 1]int
sieve [MAX_N]int // Minimum prime factor
ps [MAX_N][]int // List of prime factor counts
)
func initialize() {
if c[0][0] != 0 {
return
}
for i := 2; i < MAX_N; i++ {
if sieve[i] == 0 {
for j := i; j < MAX_N; j += i {
if sieve[j] == 0 {
sieve[j] = i
}
}
}
}
for i := 2; i < MAX_N; i++ {
x := i
for x > 1 {
p := sieve[x]
cnt := 0
for x%p == 0 {
x /= p
cnt++
}
ps[i] = append(ps[i], cnt)
}
}
c[0][0] = 1
for i := 1; i < MAX_N+MAX_P; i++ {
c[i][0] = 1
for j := 1; j <= MAX_P && j <= i; j++ {
c[i][j] = (c[i-1][j] + c[i-1][j-1]) % MOD
}
}
}
func Solution(n int, maxValue int) int {
initialize()
ans := 0
for x := 1; x <= maxValue; x++ {
mul := 1
for _, p := range ps[x] {
mul = mul * c[n+p-1][p] % MOD
}
ans = (ans + mul) % MOD
}
return ans
}