Codeforces Round #338 (Div. 2)-D. Multipliers
来源:互联网 发布:搞笑网络神曲排行榜 编辑:程序博客网 时间:2024/05/29 11:35
原题链接
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.
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).
Print one integer — the product of all divisors of n modulo 109 + 7.
22 3
36
32 3 2
1728
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.
因为所有因子都是要乘起来,所以算出每个质因子(以及它的幂)乘了几次。先预处理出每个质因子出现的次数, num[i]表示i这个质因子出现了num[i]次,那么要算j这个质因子乘的次数 p = (num[k] + 1)(k为所有质因子除了j)的乘积.
那么接下来要算j^p % MOD, 因为p会很大所以根据费马小定理j^p%MOD = j^(p%(MOD-1))%MOD;
#include <cstdio>#include <cstring>#include <algorithm>#include <stack>#include <iostream>#include <vector>#include <queue>#include <cmath>#define maxn 200005#define INF 1e15 #define MOD 1000000007typedef long long ll;using namespace std;int num[maxn];ll k1[maxn], k2[maxn];ll pow_mod(ll p, ll m){ll ans = 1;while(m){if(m&1)(ans *= p) %= MOD; (p *= p) %= MOD; m >>= 1;}return ans;}int main(){ // freopen("in.txt", "r", stdin);int m, a, maxs = 0;scanf("%d", &m);for(int i = 0; i < m; i++){scanf("%d", &a);maxs = max(maxs, a);num[a]++;}k1[1] = 1;for(int i = 2; i <= maxs; i++){if(num[i])k1[i] = k1[i-1] * (num[i] + 1)% (MOD - 1);else k1[i] = k1[i-1];}k2[maxs+1] = 1;for(int i = maxs; i >= 2; i--){if(num[i]) k2[i] = k2[i+1] * (num[i] + 1) % (MOD - 1);else k2[i] = k2[i+1];}ll ans = 1;for(int i = 2; i <= maxs; i++){if(num[i]){ll p1 = k1[i-1] * k2[i+1] % (MOD - 1), p2 = 1;for(int j = 1; j <= num[i]; j++){(p2 *= i) %= MOD;(ans *= pow_mod(p2, p1)) %= MOD;}}}printf("%I64d\n", ans);return 0;}
- Codeforces Round #338 (Div. 2) D. Multipliers
- Codeforces Round #338 (Div.2) D.Multipliers
- Codeforces Round #338 (Div. 2)-D. Multipliers
- Codeforces 615D Multipliers (Round #338 (Div. 2) D题)
- Codeforces Round #338 div 2 D. Multipliers 数论
- Codeforces Round #338 (Div. 2)D-Multipliers(数论)
- Codeforces Round #338 (Div. 2) D. Multipliers(数学、降幂公式+逆元)
- Codeforces Round #338 (Div. 2) D Multipliers(费马小定理,快速幂)
- Codeforces Round #338 (Div. 2) D. Multipliers (求因子积)
- Codeforces Round #338 (Div. 2)D. Multipliers【费马小定理+组合数学】
- Codeforces Round #338 (Div. 2)-D Multipliers(所有因数之积)
- Codeforces 615 D Multipliers
- codeforces 615D - Multipliers
- Codeforces Round #103 (Div. 2) D
- Codeforces Round #104 (Div. 2) D
- Codeforces Round #105 (Div. 2) D
- Codeforces Round #139 (Div. 2) D. Snake
- Codeforces Round #155 (Div. 2) D-rats
- [李景山php]每天laravel-20161031|Compiler.php
- lucene 新增 更新 删除索引
- [李景山php]每天laravel-20161101|CompilerInterface.php
- 搭建MFC框架启动摄像头
- org.hibernate.MappingException: Repeated column in mapping for entity
- Codeforces Round #338 (Div. 2)-D. Multipliers
- APP Store 发布新版本流程
- BGRABitmap图像操作5:画出月亮、太阳、灯光
- 操作系统概述(1)
- 阿里巴巴 “百川解码“第一期精彩回顾:热修复的坑和阿里的解
- h5开发问题收集
- oracle大批量数据加载之sqlldr使用方法
- Ubuntu14.04 + cuda 7.5 + caffe 配置
- 富文本添加中划线