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.

Example

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

P是n个质数的乘积,问P的所有因子之积是多少

先把质数整理下,假设质数p[i]出现rep[i]次

P的所有因子个数应当是∏(rep[i]+1),记为S

然后对于一个质数p[i],出现0个,1个,...rep[i]个p[i]的因子个数都是S/(rep[i]+1)

因此p[i]对于答案的贡献就是j=0~rep[i]∏(p[i]^j)^(S/(rep[i]+1))

= p[i]^(rep[i]*(rep[i]+1)/2*S/(rep[i]+1))

=p[i]^(rep[i]*S/2)

此时rep[i]*S/2太大,可能爆long long,所以还要处理:

根据欧拉定理,有a^phi(p)==1(mod p),所以p[i]^(1e9+6)==1(mod 1e9+7)

所以S*rep[i]/2可以对1e9+6取模

但是1e9+6不是质数,除二不好做,所以对它的两倍2e9+12取模,防止除2之后丢失信息

  1. #include<cstdio>
  2. #include<iostream>
  3. #include<cstring>
  4. #include<cstdlib>
  5. #include<algorithm>
  6. #include<cmath>
  7. #include<queue>
  8. #include<deque>
  9. #include<set>
  10. #include<map>
  11. #include<ctime>
  12. #define LL long long
  13. #define inf 0x7ffffff
  14. #define pa pair<int,int>
  15. #define mkp(a,b) make_pair(a,b)
  16. #define pi 3.1415926535897932384626433832795028841971
  17. #define mod 1000000007
  18. using namespace std;
  19. inline LL read()
  20. {
  21. LL x=,f=;char ch=getchar();
  22. while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
  23. while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
  24. return x*f;
  25. }
  26. LL n,cnt;
  27. LL a[];
  28. LL p[],rep[];
  29. LL ans=;
  30. inline LL quickpow(LL a,LL b,LL MOD)
  31. {
  32. LL s=;
  33. a%=MOD;
  34. b=b%(MOD-);
  35. while (b)
  36. {
  37. if (b&)s=(s*a)%MOD;
  38. a=(a*a)%MOD;
  39. b>>=;
  40. }
  41. return s;
  42. }
  43. int main()
  44. {
  45. n=read();for (int i=;i<=n;i++)a[i]=read();
  46. sort(a+,a+n+);
  47. for (int i=;i<=n;i++)
  48. if (i==||a[i]!=a[i-])
  49. {
  50. p[++cnt]=a[i];
  51. rep[cnt]=;
  52. }else rep[cnt]++;
  53. LL pro=;
  54. for (int i=;i<=cnt;i++)pro=(pro*(rep[i]+))%(*mod-);
  55. for (int i=;i<=cnt;i++)
  56. {
  57. ans=ans*quickpow(p[i],pro*rep[i]/%(*mod-),mod)%mod;
  58.  
  59. }
  60. printf("%lld\n",ans%mod);
  61. }

cf615D

也可以不把S/(rep[i]+1)和rep[i]+1约掉,搞一个{rep[i]+1}的前缀积、后缀积,就可以绕过除法把rep[i]+1挖掉

  1. #include<cstdio>
  2. #include<iostream>
  3. #include<cstring>
  4. #include<cstdlib>
  5. #include<algorithm>
  6. #include<cmath>
  7. #include<queue>
  8. #include<deque>
  9. #include<set>
  10. #include<map>
  11. #include<ctime>
  12. #define LL long long
  13. #define inf 0x7ffffff
  14. #define pa pair<int,int>
  15. #define mkp(a,b) make_pair(a,b)
  16. #define pi 3.1415926535897932384626433832795028841971
  17. #define mod 1000000007
  18. using namespace std;
  19. inline LL read()
  20. {
  21. LL x=,f=;char ch=getchar();
  22. while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
  23. while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
  24. return x*f;
  25. }
  26. LL n,cnt;
  27. LL a[];
  28. LL p[],rep[];
  29. LL s[],t[];
  30. LL phimod=;
  31. LL mod2=;
  32. LL ans=;
  33. inline LL quickpow(LL a,LL b,LL MOD)
  34. {
  35. LL s=;
  36. a%=MOD;
  37. b=b%(MOD-);
  38. while (b)
  39. {
  40. if (b&)s=(s*a)%MOD;
  41. a=(a*a)%MOD;
  42. b>>=;
  43. }
  44. return s;
  45. }
  46. int main()
  47. {
  48. n=read();for (int i=;i<=n;i++)a[i]=read();
  49. sort(a+,a+n+);
  50. for (int i=;i<=n;i++)
  51. if (i==||a[i]!=a[i-])
  52. {
  53. p[++cnt]=a[i];
  54. rep[cnt]=;
  55. }else rep[cnt]++;
  56. s[]=t[cnt+]=;
  57. for (int i=;i<=cnt;i++)
  58. {
  59. s[i]=(s[i-]*(rep[i]+))%(mod-);
  60. }
  61. for (int i=cnt;i>=;i--)
  62. t[i]=t[i+]*(rep[i]+)%(mod-);
  63. for (int i=;i<=cnt;i++)
  64. {
  65. LL ap=s[i-]*t[i+]%(mod-);
  66. ans=ans*quickpow(p[i],(rep[i]+)*rep[i]/%(mod-)*ap,mod)%mod;
  67. }
  68. printf("%lld\n",ans%mod);
  69. }

cf615D_2

cf615D Multipliers的更多相关文章

  1. CF615D Multipliers [数学]

    tags:[计数原理][乘法逆元][归纳の思想]题解(复杂度:O(mlogm)):棘手之处:n的约数多到爆炸.因此我们不妨从因子的角度来分析问题.对n分解质因数得:n = p1^a1 * p2^a2 ...

  2. Codeforces Round #338 (Div. 2) D. Multipliers 数论

    D. Multipliers 题目连接: http://codeforces.com/contest/615/problem/D Description Ayrat has number n, rep ...

  3. codeforces 615D - Multipliers

    Multipliers 题意:给定一个2e5范围内的整数m,之后输入m个2e5内的素数(当然可以重复了),问把这些输入的素数全部乘起来所得的数的约数的乘积mod(1e9+7)等于多少? 思路:对题目样 ...

  4. Codeforces 615D Multipliers (数论)

    题目链接 Multipliers 题意很明确. 很显然答案可以表示成X ^ EXP % MOD 首先我们令N为输入的n个数的乘积.并且设N = (P1 ^ C1) * (P2 ^ C2) * ... ...

  5. codeforces 615 D. Multipliers (数论 + 小费马定理 + 素数)

    题目链接: codeforces 615 D. Multipliers 题目描述: 给出n个素数,这n个素数的乘积等于s,问p的所有因子相乘等于多少? 解题思路: 需要求出每一个素数的贡献值,设定在这 ...

  6. Codeforces396A - On Number of Decompositions into Multipliers

    Portal Description 给出\(n(n\leq500)\)个\([1,10^9]\)的数,令\(m=\prod_{i=1}^n a_i\).求有多少个有序排列\(\{a_n\}\),使得 ...

  7. Alternating Direction Method of Multipliers -- ADMM

    前言: Alternating Direction Method of Multipliers(ADMM)算法并不是一个很新的算法,他只是整合许多不少经典优化思路,然后结合现代统计学习所遇到的问题,提 ...

  8. cf C On Number of Decompositions into Multipliers

    题意:给你n个数,然后把这个n个数的乘积化成n个数相乘,可以化成多少个. 思路:分解质因数,求出每一个质因子的个数,然后用组合数学中隔板法把这些质因子分成n分,答案就是所有质因子划分成n份的情况的乘积 ...

  9. CF 615D Multipliers

    题目:http://codeforces.com/contest/615/problem/D 求n的约数乘积. 设d(x)为x的约数个数,x=p1^a1+p2^a2+……+pn^an,f(x)为x的约 ...

随机推荐

  1. POJ 2831 Can We Build This One?

    Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 1728   Accepted: 643 Case Time Limit: 2 ...

  2. sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) Cannot add a NOT NULL column with default value NULL [SQL: u'ALTER TABLE address_scopes ADD COLUMN ip_version INTEGER NOT NULL']

    root@hett-virtual-machine:~# su -s /bin/sh -c "neutron-db-manage --config-file /etc/neutron/neu ...

  3. 添加 SSH 公钥

    生成 SSH 密钥 ssh-keygen -t rsa -C "YOUR_EMAIL@YOUREMAIL.COM" 获取 SSH 公钥信息 cat ~/.ssh/id_rsa.pu ...

  4. 2018_oakland_linuxmalware

    2018年oakland论文:理解linux恶意软件 论文地址:http://www.s3.eurecom.fr/~yanick/publications/2018_oakland_linuxmalw ...

  5. 四、绘图可视化之Seaborn

    Seaborn-Powerful Matplotlib Extension seaborn实现直方图和密度图 import numpy as np import pandas as pd import ...

  6. python_111_异常处理

    #1 name=['a','s'] try: print(name[3]) except: print('list index out of range')#list index out of ran ...

  7. github更换仓库

    1.找到.git目录   2.打开config文件 3.修改仓库地址 4.重新提交 git push --all origin 这样就替我们的项目换仓啦!!!^_^   分类: git 参考资料: h ...

  8. House of Spirit(fastbin)

    0x01 fastbin fastbin所包含chunk的大小为16 Bytes, 24 Bytes, 32 Bytes, … , 80 Bytes.当分配一块较小的内存(mem<=64 Byt ...

  9. ios之自定义UISwitch

    系统自带的UISwitch是这样的: 既不能写字,也不能改颜色,于是在网上找到了这么一个自定义的Switch按钮,具体出处找不见了.记录一下,怕以后找不见了. 先看下效果图: 按钮的样式很多,可以文字 ...

  10. Mac 电源管理

    在安装BatteryManager后,可以删除NullPowerMananger,AppleIntelPowerMananger, AppleIntelPowerClientMananger三个kex ...