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的约 ...
随机推荐
- asp.net 页面嵌套(非iframe)方法
前台 <div id="divUrlDetail" runat="server"> </div> 后台 protected void P ...
- couldn't be opened because you don't have permission to view it” 解决方法
I use Xcode6 GM. I encountered the same problem. What I did was to go to Build Options. Then I chang ...
- Asp.Net Core 入门(六)—— 路由
Asp.Net Core MVC的路由在Startup.cs文件中的Configure方法中进行配置,使其加入到Http请求管道中,如果不配置,那么我们所发送的请求无法得到象应. 那么该怎么配置Asp ...
- 系统学习爬虫_2_urllib
什么是urllib urlopen urllib.request.urlopen(url, data=None, [timeout, ]*, cafile=None, capath=None, cad ...
- UIScreen, UIWindow
模仿书上或网上的例子,每次最开始就是 在 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: ...
- iOS开发遇到的坑之三--使用asi框架在xcode下正常运行,但是打包时却不能进行网络访问
前言: 前两篇博客遇到的问题是前几天在实验室开发的时候遇到的,花了两三天时间在上面,今天突然心血来潮,想把这些”坑”写下来,所以才有了这两篇写的很丑的博客随笔 今天在开发时又遇到一个问题,那就是标题所 ...
- 【线段树】uoj#228. 基础数据结构练习题
get到了标记永久化 sylvia 是一个热爱学习的女孩子,今天她想要学习数据结构技巧. 在看了一些博客学了一些姿势后,她想要找一些数据结构题来练练手.于是她的好朋友九条可怜酱给她出了一道题. 给出一 ...
- ZJOI2018游记Round2
Day0 趁着空档还溜回班上了一节物理课:瓢泼之中在9:00赶往余姚,车程3h+-- 中饭在一家饭馆,味道海星. 晚上和ykh,chj,xzt溜去吃一鸣和烧烤.一鸣不错,烧烤的话我因为口腔溃疡没怎么吃 ...
- 009 CSS选择器
CSS选择器 一.基础选择器 1.通配选择器 * { border: solid; } 匹配文档中所有标签:通常指html.body及body中所有显示类的标签 2.标签选择器 div { backg ...
- (19)zabbix Applications使用介绍
介绍 Applications(我们翻译为应用程序)是item的一个组. 例如我们要监控MySQL,我们可以将所有和MySQL相关的item放到这个应用程序中. 例如MySQL的availabilit ...