time limit per test2 seconds

memory limit per test256 megabytes

inputstandard input

outputstandard output

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.

Examples

input

2

2 3

output

36

input

3

2 3 2

output

1728

Note

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.

【题解】



数论问题;先搞出质数的总数a[0];存在a[1..a[0]]中;

用cnt[x]表示x这个数字的数目;

用l[n]表示∏(cnt[a[i]]+1);i=1..n

用r[n]表示∏(cnt[a[i]]+1);i=n..a[0];

则枚举每个数字a[i];

对于1..i-1和i+1..a[0]这些数字;

它们的组合有l[i-1]*r[i+1]个;

a[i]要参与到这些组合中;

那么最后会乘进去多少个a[i]呢;

显然a[i]^x就会乘进去x个a[i];



(a[i]^1)^(l[i-1]*1*r[i+1])

(a[i]^2)^(l[i-1]*2*r[i+1])

(a[i]^3)^(l[i-1]*3*r[i+1])



(a[i]^cnt[a[i]])^(l[i-1]*cnt[a[i]]*r[i+1])

最后会全部乘起来;

即a[i]^(l[i-1]r[i+1](1+2+3..+cnt[a[i]]))

即a[i]^(l[i-1]r[i+1]*cnt[a[i]](cnt[a[i]]+1)/2);

这个数字的指数是很恐怖的;

a[i]^(l[i-1]r[i+1]*cnt[a[i]](cnt[a[i]]+1)/2)

需要用费马小定理搞一搞;

下面是证明;

最上面那行是费马小定理;



这个费马小定理要求p和a是互质的;

而P是1e9+7是质数

a[i]最大20W小于P显然a[i]和p互质;则

a[i]^(l[i-1]r[i+1]*cnt[a[i]](cnt[a[i]]+1)/2) % p==a[i]^(l[i-1]r[i+1]*cnt[a[i]](cnt[a[i]]+1)/2%(p-1)) % p;

然后快速幂搞下就好;

#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#include <stack>
#include <string>
#define lson L,m,rt<<1
#define rson m+1,R,rt<<1|1
#define LL long long using namespace std; const int MAXN = 2e5;
const int MOD = 1e9+7;
const int dx[5] = {0,1,-1,0,0};
const int dy[5] = {0,0,0,-1,1};
const double pi = acos(-1.0); LL ans = 1,l[MAXN+100],r[MAXN+100],cnt[MAXN+100];
int m;
LL a[MAXN+100] = {0};
vector <LL> pre[MAXN]; void input_LL(LL &r)
{
r = 0;
char t = getchar();
while (!isdigit(t) && t!='-') t = getchar();
LL sign = 1;
if (t == '-')sign = -1;
while (!isdigit(t)) t = getchar();
while (isdigit(t)) r = r * 10 + t - '0', t = getchar();
r = r*sign;
} void input_int(int &r)
{
r = 0;
char t = getchar();
while (!isdigit(t)&&t!='-') t = getchar();
int sign = 1;
if (t == '-')sign = -1;
while (!isdigit(t)) t = getchar();
while (isdigit(t)) r = r * 10 + t - '0', t = getchar();
r = r*sign;
} LL ksm(LL a,LL x)
{
if (x==0)
return 1;
LL temp = ksm(a,x>>1);
temp = (temp*temp)%MOD;
if (x&1)
temp = (temp*a)%MOD;
return temp;
} int main()
{
input_int(m);
for (int i = 1;i <= m;i++)
{
int x;
input_int(x);
cnt[x]++;
}
for (int i = 2;i <= MAXN;i++)
if (cnt[i])
a[++a[0]] = i;
l[0] = 1;r[a[0]+1] = 1;
for (int i = 1;i<=a[0];i++)
l[i] = (l[i-1]*(cnt[a[i]]+1))%(MOD-1);
for (int i = a[0];i>=1;i--)
r[i] = (r[i+1]*(cnt[a[i]]+1))%(MOD-1);
for (int i = 1;i <= a[0];i++)
{
LL temp1 = ((cnt[a[i]]*(cnt[a[i]]+1))/2)%(MOD-1);
LL temp2 = (l[i-1]*r[i+1])%(MOD-1);
LL temp = ksm(a[i],(temp1*temp2)%(MOD-1));
ans = (ans * temp)%MOD;
}
printf("%I64d\n",ans);
return 0;
}

【14.67%】【codeforces 615D】Multipliers的更多相关文章

  1. 【 BowWow and the Timetable CodeForces - 1204A 】【思维】

    题目链接 可以发现 十进制4 对应 二进制100 十进制16 对应 二进制10000 十进制64 对应 二进制1000000 可以发现每多两个零,4的次幂就增加1. 用string读入题目给定的二进制 ...

  2. 【24.67%】【codeforces 551C】 GukiZ hates Boxes

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  3. 【26.67%】【codeforces 596C】Wilbur and Points

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  4. 【中途相遇法】【STL】BAPC2014 K Key to Knowledge (Codeforces GYM 100526)

    题目链接: http://codeforces.com/gym/100526 http://acm.hunnu.edu.cn/online/?action=problem&type=show& ...

  5. 【codeforces 67A】Partial Teacher

    [题目链接]:http://codeforces.com/problemset/problem/67/A [题意] 给一个长度为n-1的字符串; 每个字符串是'L','R','='这3种字符中的一个; ...

  6. 【77.78%】【codeforces 625C】K-special Tables

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

  7. 【codeforces 754D】Fedor and coupons

    time limit per test4 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  8. 【codeforces 760A】Petr and a calendar

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  9. 【codeforces 750E】New Year and Old Subsequence

    time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

随机推荐

  1. 洛谷—— P1967 货车运输 || COGS——C 1439. [NOIP2013]货车运输

    https://www.luogu.org/problem/show?pid=1967#sub  ||  http://www.cogs.pro/cogs/problem/problem.php?pi ...

  2. 【codeforces 434 div 1 A】Did you mean...

    [链接]h在这里写链接 [题意] 让你维护一段序列. 这段序列,不会出现连续3个以上的辅音. (或者一块全是辅音则也可以) (用空格可以断开连续次数); 要求空格最小. [题解] 模拟着,别让它出现连 ...

  3. vagrant 的安装与使用

    1. 安装 ubuntu 安装vagrant过程 ubuntu 安装 vagrant 时需要首先安装 virtualbox: (1)下载安装与当前 ubuntu 版本相适应的 virtualbox 安 ...

  4. HZK16应用实例

    在C51中,HZK16汉字库的使用(mydows's Blog转载) 定义如下: unsigned char str[]="我" 个字节长度,内容为"我"的GB ...

  5. fatfs的设置

    官方网址:file:///E:/%E5%8D%95%E7%89%87%E6%9C%BA/FATFS/ff13a/documents/doc/config.html 关于多个文件同时打开的配置::在ff ...

  6. 谈谈我对P2P网络借贷的一些看法

    北漂期间,只知道互联网金融非常火,相关创业公司和项目也非常多.2013年,最火的是余额宝等宝宝类产品.当时的收益率达到了7%,流动性如此高的情况下,竟达到这么高的收益率,我简直不敢相信.另外,当时考虑 ...

  7. 用css3解决移动端页面自适应横屏竖屏的思考

    之前对于横屏的webapp做过一些尝试,可是始终不是非常好的解决方式,前段时间又接触了类似的需求,尝试了感觉更好的解决方式. 之前的方法写的博客:移动网页横竖屏兼容适应的一些体会 这里举的样例还是平时 ...

  8. Linux下多线程查看工具(pstree、ps、pstack),linux命令之-pstree使用说明, linux 查看线程状态。 不指定

    0.最常用 pstree:[root@iZ25dcp92ckZ temp]# pstree -a|grep multe  |       |   `-multepoolser  |       |   ...

  9. 机器学习01-kNN邻近算法

    k-近邻算法 概述:k-近邻算法採用測量不同特征值之间的距离方法进行分类 长处:精度高.对于异常值不敏感.无数据输入假定 缺点:计算复杂度高,空间复杂度高,而且它没有办法各处基础数据的一些内部信息数据 ...

  10. [Vue] Preload Data using Promises with Vue.js and Nuxt.js

    Nuxt.js allows you to return a Promise from your data function so that you can asynchronously resolv ...