cf615D Multipliers
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
2
2 3
36
3
2 3 2
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之后丢失信息
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<ctime>
#define LL long long
#define inf 0x7ffffff
#define pa pair<int,int>
#define mkp(a,b) make_pair(a,b)
#define pi 3.1415926535897932384626433832795028841971
#define mod 1000000007
using namespace std;
inline LL read()
{
LL x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
LL n,cnt;
LL a[];
LL p[],rep[];
LL ans=;
inline LL quickpow(LL a,LL b,LL MOD)
{
LL s=;
a%=MOD;
b=b%(MOD-);
while (b)
{
if (b&)s=(s*a)%MOD;
a=(a*a)%MOD;
b>>=;
}
return s;
}
int main()
{
n=read();for (int i=;i<=n;i++)a[i]=read();
sort(a+,a+n+);
for (int i=;i<=n;i++)
if (i==||a[i]!=a[i-])
{
p[++cnt]=a[i];
rep[cnt]=;
}else rep[cnt]++;
LL pro=;
for (int i=;i<=cnt;i++)pro=(pro*(rep[i]+))%(*mod-);
for (int i=;i<=cnt;i++)
{
ans=ans*quickpow(p[i],pro*rep[i]/%(*mod-),mod)%mod; }
printf("%lld\n",ans%mod);
}
cf615D
也可以不把S/(rep[i]+1)和rep[i]+1约掉,搞一个{rep[i]+1}的前缀积、后缀积,就可以绕过除法把rep[i]+1挖掉
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<ctime>
#define LL long long
#define inf 0x7ffffff
#define pa pair<int,int>
#define mkp(a,b) make_pair(a,b)
#define pi 3.1415926535897932384626433832795028841971
#define mod 1000000007
using namespace std;
inline LL read()
{
LL x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
LL n,cnt;
LL a[];
LL p[],rep[];
LL s[],t[];
LL phimod=;
LL mod2=;
LL ans=;
inline LL quickpow(LL a,LL b,LL MOD)
{
LL s=;
a%=MOD;
b=b%(MOD-);
while (b)
{
if (b&)s=(s*a)%MOD;
a=(a*a)%MOD;
b>>=;
}
return s;
}
int main()
{
n=read();for (int i=;i<=n;i++)a[i]=read();
sort(a+,a+n+);
for (int i=;i<=n;i++)
if (i==||a[i]!=a[i-])
{
p[++cnt]=a[i];
rep[cnt]=;
}else rep[cnt]++;
s[]=t[cnt+]=;
for (int i=;i<=cnt;i++)
{
s[i]=(s[i-]*(rep[i]+))%(mod-);
}
for (int i=cnt;i>=;i--)
t[i]=t[i+]*(rep[i]+)%(mod-);
for (int i=;i<=cnt;i++)
{
LL ap=s[i-]*t[i+]%(mod-);
ans=ans*quickpow(p[i],(rep[i]+)*rep[i]/%(mod-)*ap,mod)%mod;
}
printf("%lld\n",ans%mod);
}
cf615D_2
cf615D Multipliers的更多相关文章
- CF615D Multipliers [数学]
tags:[计数原理][乘法逆元][归纳の思想]题解(复杂度:O(mlogm)):棘手之处:n的约数多到爆炸.因此我们不妨从因子的角度来分析问题.对n分解质因数得:n = p1^a1 * p2^a2 ...
- Codeforces Round #338 (Div. 2) D. Multipliers 数论
D. Multipliers 题目连接: http://codeforces.com/contest/615/problem/D Description Ayrat has number n, rep ...
- codeforces 615D - Multipliers
Multipliers 题意:给定一个2e5范围内的整数m,之后输入m个2e5内的素数(当然可以重复了),问把这些输入的素数全部乘起来所得的数的约数的乘积mod(1e9+7)等于多少? 思路:对题目样 ...
- Codeforces 615D Multipliers (数论)
题目链接 Multipliers 题意很明确. 很显然答案可以表示成X ^ EXP % MOD 首先我们令N为输入的n个数的乘积.并且设N = (P1 ^ C1) * (P2 ^ C2) * ... ...
- codeforces 615 D. Multipliers (数论 + 小费马定理 + 素数)
题目链接: codeforces 615 D. Multipliers 题目描述: 给出n个素数,这n个素数的乘积等于s,问p的所有因子相乘等于多少? 解题思路: 需要求出每一个素数的贡献值,设定在这 ...
- Codeforces396A - On Number of Decompositions into Multipliers
Portal Description 给出\(n(n\leq500)\)个\([1,10^9]\)的数,令\(m=\prod_{i=1}^n a_i\).求有多少个有序排列\(\{a_n\}\),使得 ...
- Alternating Direction Method of Multipliers -- ADMM
前言: Alternating Direction Method of Multipliers(ADMM)算法并不是一个很新的算法,他只是整合许多不少经典优化思路,然后结合现代统计学习所遇到的问题,提 ...
- cf C On Number of Decompositions into Multipliers
题意:给你n个数,然后把这个n个数的乘积化成n个数相乘,可以化成多少个. 思路:分解质因数,求出每一个质因子的个数,然后用组合数学中隔板法把这些质因子分成n分,答案就是所有质因子划分成n份的情况的乘积 ...
- CF 615D Multipliers
题目:http://codeforces.com/contest/615/problem/D 求n的约数乘积. 设d(x)为x的约数个数,x=p1^a1+p2^a2+……+pn^an,f(x)为x的约 ...
随机推荐
- 访问修饰符(C# 参考)
第一篇 就抄写了一下下MSDN上面的东西练练手吧!!! 访问修饰符是一些关键字,用于指定声明的成员或类型的可访问性. 本节介绍四个访问修饰符: public protected ...
- UWP中获取Encoding.Default
Encoding.GetEncoding(0); 即可
- hibernate的注解
1.many-to-one @ManyToOne @JoinColumn(name = "user_id") 2.many-to-many /** * 双向关联关系中,有且仅有一端 ...
- 菜鸟学习Cocos2d-x 3.x——内存管理
菜鸟学习Cocos2d-x 3.x——内存管理 2014-12-10 分类:Cocos2d-x / 游戏开发 阅读(394) 评论(6) 亘古不变的东西 到现在,内存已经非常便宜,但是也不是可以 ...
- 【模板】任意模数NTT
题目描述: luogu 题解: 用$fft$水过(什么$ntt$我不知道). 众所周知,$fft$精度低,$ntt$处理范围小. 所以就有了任意模数ntt神奇$fft$! 意思是这样的.比如我要算$F ...
- webpack-dev-server proxy代理
一个最简单的代理例子:index.html中有如下代码 fetch('/api/pub/article/list?pageSize=2').then((data)=>{ return data. ...
- 纯 CSS 创作一个小球绕着圆环盘旋的动画
效果预览 在线演示 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/gKxyWo 可交互视频 ...
- Processed foods make us fatter easily
From Business Insider Here's an experiment: sit alone in a hospital room for two weeks and eat nothi ...
- python面向对象(反射)(四)
1. isinstance, type, issubclass isinstance: 判断你给对象是否是xx类型的. (向上判断 type: 返回xxx对象的数据类型 issubclass: 判断x ...
- LeetCode(109) Convert Sorted List to Binary Search Tree
题目 Given a singly linked list where elements are sorted in ascending order, convert it to a height b ...