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 数论的更多相关文章

  1. Codeforces Round #338 (Div. 2)

    水 A- Bulbs #include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 1 ...

  2. Codeforces Round #338 (Div. 2) E. Hexagons 讨论讨论

    E. Hexagons 题目连接: http://codeforces.com/contest/615/problem/E Description Ayrat is looking for the p ...

  3. 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 ...

  4. Codeforces Round #338 (Div. 2) B. Longtail Hedgehog dp

    B. Longtail Hedgehog 题目连接: http://www.codeforces.com/contest/615/problem/B Description This Christma ...

  5. Codeforces Round #338 (Div. 2) A. Bulbs 水题

    A. Bulbs 题目连接: http://www.codeforces.com/contest/615/problem/A Description Vasya wants to turn on Ch ...

  6. Codeforces Round #338 (Div. 2) D 数学

    D. Multipliers time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

  7. Codeforces Round #338 (Div. 2) B dp

    B. Longtail Hedgehog time limit per test 3 seconds memory limit per test 256 megabytes input standar ...

  8. 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互 ...

  9. 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 ...

随机推荐

  1. 15、NFC技术:使用Android Beam技术传输文件

    传输文件的API 从Android4.1开始,NfcAdapter类增加了如下两个推送数据的方法. NfcAdapter.setBeamPushUris NfcAdapter.setBeamPushU ...

  2. LR之Java虚拟用户

    1.认识Java虚拟用户 2.Java虚拟用户的适用范围

  3. 【LeetCode】237 & 203 - Delete Node in a Linked List & Remove Linked List Elements

    237 - Delete Node in a Linked List Write a function to delete a node (except the tail) in a singly l ...

  4. 上海洋码头(www.ymatou.com)急招技术人才(职位:互联网软件开发工程师,.NET网站架构师,Web前端开发工程师,高级测试工程师,产品经理)

    对公司招聘职位有兴趣的童鞋可以把简历发送到zhangzhiqiang@ymatou.com,我们HR会快速给你答复. 互联网软件开发工程师 岗位职责: 1.参与洋码头各个平台(www.ymatou.c ...

  5. Epic - Decimal Number

    Let the user enter a decimal number. Therange allowed is 0.0001 to 0.9999. Only four decimal places ...

  6. 数往知来 ADO.NET <八>

    ADO.NET基础 学习目的:通过程序访问数据库 ,ADO.NET就是一组类库, -->connection   用来连接数据库的类 语法:首先需要一个连接字符串 -->以SQL serv ...

  7. 【加解密】关于DES加密算法的JAVA加密代码及C#解密代码

    JAVA加密: package webdomain; import java.security.Key; import java.security.spec.AlgorithmParameterSpe ...

  8. 浅谈Spark(1) - Overview

    Spark是UC Berkeley AMP lab所开源的类Hadoop MapReduce的通用并行框架,Spark,拥有Hadoop MapReduce所具有的优点:但不同于MapReduce的是 ...

  9. Thu夏令营 总结

    感觉这次thu夏令营简直就是爆RP啊 竟然签了无条件本一 [Waring]RP已空 话说这次考试设定 竟然是下午两点开始考试 考到五点- - 导致中午必须午睡 宾馆里清华也不近 按原本试机安排到12点 ...

  10. 验证dictionary重复键

    if (dict.ContainsKey("sadsa")) { }