結果

問題 No.1237 EXP Multiple!
ユーザー sirosaisirosai
提出日時 2022-09-03 23:20:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,068 bytes
コンパイル時間 1,524 ms
コンパイル使用メモリ 168,620 KB
実行使用メモリ 11,548 KB
最終ジャッジ日時 2024-04-28 19:48:26
合計ジャッジ時間 5,190 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,624 KB
testcase_01 TLE -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n, m) for (ll i = n; i < (ll)(m); i++)
#define _rep(i, n, m) for (ll i = n; i <= (ll)(m); i++)
using ll = long long;

// recursive is slow ..orz
ll rfactorial(ll k) {
    // ret k*(k-1)*...*1
    if (k == 1)
        return 1;
    else
        return k * rfactorial(k - 1);
}
ll factorial(ll k) {
    ll ret = 1;
    rep(i, 1, k + 1) ret *= i;
    return ret;
}

int main() {
    // A1,...,AN
    // Ai>=0
    // prod{ A_k^{A_k!} }
    // exp
    // 1,2,3
    // 1^{1!} + 2^{2!} + 3^{3!}
    // 1 + 2^2 + 3^6
    // mod (10^9+7)

    ll mod = 1e9 + 7;
    int N;
    cin >> N;
    ll A[N];
    rep(i, 0, N) cin >> A[i];
    // overflow ver
    ll ret = 1;

    // cout << factorial(3) << endl;

    // 結局 k^n (mod p) はk(mod p)ではないか?
    // 3^3 % 7 = (9 % 7 * 3 % 7 ) % 7 = 6
    rep(i, 0, N) {  // A[0] ... A[N-1]
        // A[i]についてはA[i]! の積を取る
        ret = ret * ((ll)pow(A[i], factorial(A[i])));
    }

    // 3^6 * 3^6 * 3^6 = 3^18

    cout << mod % ret << endl;
}
0