Ayrat has number n, represented as it's prime factorization pi of size m, i.e. n = p1·p2·...·pm. Ayrat got secret information that that the product of all divisors of n taken modulo 109 + 7 is the password to the secret data base. Now he wants to calculate this value.
The first line of the input contains a single integer m (1 ≤ m ≤ 200 000) — the number of primes in factorization of n.
The second line contains m primes numbers pi (2 ≤ pi ≤ 200 000).
Print one integer — the product of all divisors of n modulo 109 + 7.
2 2 3
36
3 2 3 2
1728
In the first sample n = 2·3 = 6. The divisors of 6 are 1, 2, 3 and 6, their product is equal to 1·2·3·6 = 36.
In the second sample 2·3·2 = 12. The divisors of 12 are 1, 2, 3, 4, 6 and 12. 1·2·3·4·6·12 = 1728.
题意:给定m个质因子p[],有p[1]*p[2]*...*p[m] == n,问n所有因子的乘积 % 1e9 + 7。
思路:组合数学。
先把所有因子存起来,并统计个数为top(不相同的)。考虑每个质因子rec[i]做出的贡献,结果为rec[i]^num。
其中num为rec[i]在n所有因子乘积中存在的个数。
定义1-i质因子的组合方案数l[i],后i-top个质因子的组合方案数r[i]。
考虑第i个质因子的状态,取或不取,不取有l[i-1],取则有l[i-1] * cnt[rec[i]](可能取1 - cnt[rec[i]])
同理求法r[]。
对于一个质因子rec[i],可以与前、后组合,那么它的可组合方案数为temp = l[i-1] * r[i+1]。
若该质因子有Num个,则有方案rec[i] * temp 、rec[i] * rec[i] * temp... rec[i]^(Num) * temp。
统计rec[i]出现次数有num = (Num+1) * Num/2 * temp.下面ans *= rec[i] ^ num就好了。
num值很大,费马小定理a^n = a^(n%(m-1)) (%m)搞下就ok了。也就是说num % (1e9+7-1)。
AC代码:
#include
#include
#include
#include
#include
#include
#include
#include
#include