I've been trying to solve this problem:
Find Euler's totient function of binomial coefficient C(n, m) = n! / (m! (n - m)!)
modulo 10^9 + 7, m <= n < 2 * 10^5
.
One of my ideas was that first, we can precalculate the values of phi(i)
for all i from 1 to n in linear time, also we can calculate all inverses to numbers from 1 to n modulo 10^9 + 7 using, for example, Fermat's little theorem. After that, we know, that, in general, phi(m * n) = phi(m) * phi(n) * (d / fi(d)), d = gcd(m, n)
. Because we know that gcd((x - 1)!, x) = 1, if x is prime, 2 if x = 4, and x in all other cases
, we can calculate phi(x!)
modulo 10^9 + 7 in linear time. However, in the last step, we need to calculate phi(n! / ((m! (n - m)!)
, (if we already know the function for factorials), so, if we are using this method, we have to know gcd(C(n, m), m! (n - m)!)
, and I don't know how to find it.
I've also been thinking about factorizing the binomial coefficient, but there seems no efficient way to do this.
Any help would be appreciated.