Official

C - Multiple Sequences Editorial by evima


Let us try to find the answer for each \(A_N = 1, 2, \ldots, M\) and sum them up. The answer for fixed \(A_N\) can be found as the product of \(n\) binomial coefficients, where \(n\) is the number of prime factors of \(A_N\), by focusing on where in the sequence the number of times each prime factor is multiplied increases.

The total number of prime factors of \(i = 1, 2, \ldots, M\) can be evaluated as \(O\left(M\log M\right)\). Thus, excluding the precomputation for binomial coefficients, we can solve the problem in \(O\left(M\log M\right)\) time.

posted:
last update: