Codeforces Round #338 (Div. 2) D Multipliers(费马小定理,快速幂)

大神的题解:(http://blog.csdn.net/sinat_30062549/article/details/50489302)

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
using namespace std;
const long long mod = 1e9+7;
long long num[200100];
long long quick_power(long long n,long long m)
{
    long long ans = 1;
    while (m) {
        if (m&1) {
            ans = ans*n%mod;
        }
        n = n*n%mod;
        m>>=1;
    }
    return ans;
}
int main() {
    int m;
    cin>>m;
    for (int i = 1; i<=200000; i++) {
        num[i] = 0;
    }
    for (int i = 1; i<=m; i++) {
        int x;
        cin>>x;
        num[x]++;
    }
    long long sum = 1;
    long long ans = 1;
    for (int i = 1; i<=200000; i++) {
        if (num[i]) {
            long long cnt = (num[i]+1)*num[i]/2;
            cnt = quick_power(i, cnt);
            ans = quick_power(ans, num[i]+1)*quick_power(cnt, sum);
            ans %= mod;
            sum *= num[i]+1;
            sum %= (mod-1);
        }
    }
    cout<<ans<<endl;
    return 0;
}
已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页