传送门:点击打开链接
题意:这些质数的乘积所组成的那个数,求这个数的所有约数的乘积,取模1e9+7
思路:先分别求出每个数出现的个数,那么对于这一类的数,计算它对答案的贡献。首先,假如最多有s个这样的数字,假设这个数为a,那么我要考虑,对于一个约数,出现了1次,2次......s次,然后其他的质数的出现情况有多少种呢,假如其他质数出现的次数为cnt[i],那么就有P = (cnt[1]+1)*(cnt[2]+1)*....*(cnt[i-1]+1)*(cnt[i+1]+1)*...(cnt[n]+1),那么答案就是power(a,P*(cnt[i]+1)*cnt[i]/2)
对于P,我们可以用前缀思想来维护。对于a^b%mod,因为b很大,但是根据费马小定理,b应该对mod-1取模
所以我们在幂上面应该对mod-1取模,然后一个快速幂,就搞定啦
#include<map>
#include<set>
#include<cmath>
#include<ctime>
#include<stack>
#include<queue>
#include<cstdio>
#include<cctype>
#include<string>
#include<vector>
#include<cstring>
#include<iomanip>
#include<iostream>
#include<algorithm>
#include<functional>
#define fuck(x) cout<<"["<<x<<"]"
#define FIN freopen("input.txt","r",stdin)
#define FOUT freopen("output.txt","w+",stdout)
using namespace std;
typedef long long LL;
typedef pair<int, int>PII;
const int MX = 2e5 + 5;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
LL L[MX], R[MX];
int A[MX], B[MX], cnt[MX], rear;
LL power(LL a, LL b, LL mod) {
LL ret = 1;
while(b) {
if(b & 1) ret = ret * a % mod;
a = a * a % mod;
b >>= 1;
}
return ret;
}
int main() {
int n; //FIN;
while(~scanf("%d", &n)) {
rear = 0;
for(int i = 1; i <= n; i++) {
scanf("%d", &A[i]);
}
sort(A + 1, A + 1 + n);
LL ans = 1;
int l, r, w;
L[0] = 1;
for(l = 1; l <= n; l = r + 1) {
for(r = l; r < n && A[r + 1] == A[r]; r++);
w = r - l + 1;
B[++rear] = A[l]; cnt[rear] = w;
L[rear] = L[rear - 1] * (cnt[rear] + 1) % (mod - 1);
}
R[rear + 1] = 1;
for(r = rear; r >= 1; r--) {
R[r] = R[r + 1] * (cnt[r] + 1) % (mod - 1);
}
for(int i = 1; i <= rear; i++) {
LL p = (LL)cnt[i] * (cnt[i] + 1) / 2 % (mod - 1) * L[i - 1] % (mod - 1) * R[i + 1] % (mod - 1);
ans = ans * power(B[i], p, mod) % mod;
}
printf("%I64d\n", ans);
}
return 0;
}