Multipliers

10 篇文章 0 订阅
3 篇文章 0 订阅

Description

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

Input
2
2 3
Output
36
Input
3
2 3 2
Output
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.


这里要求算出m个数相乘结果的因子相乘%10^9+7的结果,因为这些数全部都是素数,所以就不需

分解,如果不是素数只需要分解成素数就可以了。

解法:

可以直接统计每个素数出现的次方是多少就行了

算法:

当前素数可以取1-ai(ai表示此种素数的个数)

那么其前面所有的数取法有(a1+1)*(a2+1)...*(a[i-1]+1)*(a[i+1]+1)...*(an+1)

这样就可以直接算出次方是多少了,但是可能longlong都存不下,

那么就要用一个定理费马小定理:a^(p-1)%p=1,当a,p互素时。

然后用快速幂算出乘积取模就可以了。

#include <stdio.h>
#include <algorithm>
#define LL long long
#define MOD 1000000007
const int maxn = 200005;
LL a[maxn], f_mut[maxn], l_mut[maxn], v[maxn];
LL cnt[maxn];
LL quick_power ( LL val, LL n )
{
    LL ret = 1;
    while ( n )
    {
        if ( n & 1 )
            ret = ret*val%MOD;
        val = val*val%MOD;
        n >>= 1;
    }
    return ret;
}
int main ( )
{
    int n, k;
    scanf ( "%d", &n );
    for ( int i = 1; i <= n; i ++ )
        scanf ( "%I64d", &a[i] );
    std :: sort ( a+1, a+1+n );
    k = 1;
    cnt[1] = 1;
    for ( int i = 2; i <= n; i ++ ) //统计出相同素数的个数
    {
        if ( a[i] == a[i-1] )
            cnt[k] ++;
        else
        {
            k ++;
            cnt[k] = 1;
            a[k] = a[i];
        }
    }
    l_mut[k+1] = 1;
    for ( int i = k; i >= 1; i -- )
        l_mut[i] = l_mut[i+1]*( cnt[i]+1 )%( MOD-1 );
    f_mut[0] = 1;
    for ( int i = 1; i <= k; i ++ )
        f_mut[i] = f_mut[i-1]*( cnt[i]+1 )%( MOD-1 );
    for ( int i = 1; i <= k; i ++ )
    //算出前后与当前素数组成的次方,并采用费马小定理对MOD-1进行取余
        v[i] = ( 1+cnt[i] )*cnt[i]/2%( MOD-1 )*f_mut[i-1]%( MOD-1 )*l_mut[i+1]%( MOD-1 );
    LL ans = 1;
    for ( int i = 1; i <= k; i ++ )
        ans = ans*quick_power ( a[i], v[i] )%MOD;
    printf ( "%I64d", ans );
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值