escription
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.
Input
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).
Output
Print one integer — the product of all divisors of n modulo 109 + 7.
Sample Input
2 2 3
36
3 2 3 2
1728
Hint
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.
题意:题目很清楚,给你n个质因数,求他们的积的所有因子之积(包括1和本身)。
(看到题目很懵圈~想着要是知道所有因子该有多好~(那还做个P的题目))。
思路:(我也是看题解的,简单翻译一下吧.)
题目已给n个质因数,这个条件好好哦,如果不是,那还得自己求质因数~.我们设n个质因数之积为x,那么x的因子个数必定是由这n个质因数两两乘或者是一个数本身.直接给出公式:x=p1^a1*p2^a2*p3^a3*.......*pn^an,
那么设d(x)为x的因子个数:d(x)=(a1+1)*(a2+1)*(a3+1)*...*(an+1);
(这个公式可以这样理解:有a1个p1,那么可以选0个,1个,2个...a1个,所以有(a1+1)。)
x其中的一个因子m,那么也就有x/m这个因子的存在。那么就有d(x)/2对这样的因子,
所以设f(x)为最终答案,给出公式f(x)=x^(d(x)/2)。
那么要是x是个完全平方数,d(x)不是个奇数吗?怎么办?要多乘一个sqrt(x).?
其实并不用。
因为x很大,d(x)/2也很大,我们并不能直接求取。
那么就要拆开取模,怎么拆啊?d(ab)=d(a)*d(b),f(ab)=f(a)^d(b)*f(b)^d(a)。
所以对于一个x是完全平方数,就有公式f(p^k)=p^(k*(k+1)/2),可以直接得到,所以不用多乘sqrt(x)(将fx公式带入得)。
拆完x,那指数d(x)/2很大咋办?那么由费马小定理得:,所以指数只能对(mod-1)取模。(因为它处在指数位置,所以不能随便对mod直接取模)。
真不容易~
附上AC代码: