Codeforces Round #338 (Div. 2) D. Multipliers 数论
D. Multipliers
题目连接:
http://codeforces.com/contest/615/problem/D
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).rst line of the input contains the string s — the coating that is present in the shop. Second line contains the string t — the coating Ayrat wants to obtain. Both strings are non-empty, consist of only small English letters and their length doesn't exceed 2100.
Output
Print one integer — the product of all divisors of n modulo 109 + 7.
Sample Input
2
2 3
Sample Output
36
Hint
题意
给你一个数的质因数,然后让你求出这个数所有因数的乘积
题解:
和hdu 5525很像,某场BC的原题
对于每个质因子,对答案的贡献为p^(d[p] * (d[p]-1) \ 2 * d[s])
d[p]表示p的因子数量,d[s]表示s这个数的因子数量
数量可以由因子数量定理求得,d[s] = (a1+1)(a2+1)...(an+1),a1.a2.a3表示s的质因子的次数。
但是由于指数可能很大,所以我们就需要使用费马小定理就好了
但是又有除2的操作,mod-1有不是质数,不存在逆元,所以先对2(mod-1)取模。
代码
#include<bits/stdc++.h>
using namespace std;
#define maxn 200005
long long mod = 1e9+7;
long long mod2 = 2LL*(mod - 1);
long long quickpow(long long a,long long b,long long c)
{
long long ans = 1;
while(b)
{
if(b&1)ans = ans * a % c;
a = a * a % c;
b>>=1;
}
return ans;
}
int cnt[maxn];
int p[maxn];
int vis[maxn];
int main()
{
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%d",&p[i]);
cnt[p[i]]++;
}
long long tot = 1;
for(int i=1;i<=n;i++)
{
if(vis[p[i]])continue;
vis[p[i]]=1;
tot = tot*(cnt[p[i]]+1)%mod2;//求因子数
}
memset(vis,0,sizeof(vis));
long long ans = 1;
for(int i=1;i<=n;i++)
{
if(vis[p[i]])continue;
vis[p[i]]=1;
ans=ans*quickpow(p[i],(tot*cnt[p[i]]/2)%mod2,mod)%mod;//每个数的贡献,费马小定理
}
cout<<ans<<endl;
}
Codeforces Round #338 (Div. 2) D. Multipliers 数论的更多相关文章
- Codeforces Round #338 (Div. 2)
水 A- Bulbs #include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 1 ...
- Codeforces Round #338 (Div. 2) E. Hexagons 讨论讨论
E. Hexagons 题目连接: http://codeforces.com/contest/615/problem/E Description Ayrat is looking for the p ...
- Codeforces Round #338 (Div. 2) C. Running Track dp
C. Running Track 题目连接: http://www.codeforces.com/contest/615/problem/C Description A boy named Ayrat ...
- Codeforces Round #338 (Div. 2) B. Longtail Hedgehog dp
B. Longtail Hedgehog 题目连接: http://www.codeforces.com/contest/615/problem/B Description This Christma ...
- Codeforces Round #338 (Div. 2) A. Bulbs 水题
A. Bulbs 题目连接: http://www.codeforces.com/contest/615/problem/A Description Vasya wants to turn on Ch ...
- Codeforces Round #338 (Div. 2) D 数学
D. Multipliers time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
- Codeforces Round #338 (Div. 2) B dp
B. Longtail Hedgehog time limit per test 3 seconds memory limit per test 256 megabytes input standar ...
- Codeforces Round #392(Div 2) 758F(数论)
题目大意 求从l到r的整数中长度为n的等比数列个数,公比可以为分数 首先n=1的时候,直接输出r-l+1即可 n=2的时候,就是C(n, 2)*2 考虑n>2的情况 不妨设公比为p/q(p和q互 ...
- Codeforces Round #338 (Div. 2) B. Longtail Hedgehog 记忆化搜索/树DP
B. Longtail Hedgehog This Christmas Santa gave Masha a magic picture and a pencil. The picture con ...
随机推荐
- 继承TextView简单画一个尺子
import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; impor ...
- Android 获取assets的绝对路径
第一种方法: String path = "file:///android_asset/文件名"; 第二种方法: InputStream abpath = get ...
- 小数点输出精度控制问题 .xml
pre{ line-height:1; color:#9f1d66; background-color:#d2d2d2; font-size:16px;}.sysFunc{color:#5d57ff; ...
- Win7+VS2013初试Thrift
win7环境下VS2013编译boost_1_58_0步骤: 官网下载boost_1_58_0(直接下载),解压 cmd窗口cd到boost_1_58_0,执行bootstrap.bat cmd窗口获 ...
- visual assistent 过期
VA功能超级好使,下载的一般都有时间限制,但又不想买正版. 我的是32位系统 vs2008: 将VA_X.dll文件拷到 (x86)C:\Program Files\Visual Assist X\ ...
- Tcl之Intro
Tool command language, a widely used scripting tool that was deveoped for controlling and extending ...
- ninject学习笔记一:IOC的实现
这篇文章主要介绍ninject在IOC方面的实现,至于IOC的含义,网络资源很丰富,我这儿就不再赘述了.官方的文档其实挺好的,只是本人英语很烂,看起来比较费劲,下面这些东西是看官方的代码推敲的,我觉得 ...
- 开源框架DNN简介以及安装
donetnuke 是一款免费的开源cms框架,目前也有收费版,不过免费版也可以适应大家大部分的需求.我前些阵子是老板让我在20天内,做好一个官网并且发布,并且指定使用dnn这个框架,考虑到又可以学习 ...
- 流式计算之Storm简介
Storm是一个分布式的.容错的实时计算系统,遵循Eclipse Public License 1.0,Storm可以方便地在一个计算机集群中编写与扩展复杂的实时计算,Storm之于实时处理,就好比H ...
- 使用ReflectionTestUtils解决依赖注入
概述 当使用junit来测试Spring的代码时,为了减少依赖,需要给对象的依赖,设置一个mock对象,但是由于Spring可以使用@Autoware类似的注解方式,对私有的成员进行赋值,此时无法 ...