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代碼: