結果

問題 No.573 a^2[i] = a[i]
ユーザー kappybarkappybar
提出日時 2020-05-12 22:02:21
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 33 ms / 2,000 ms
コード長 1,210 bytes
コンパイル時間 1,494 ms
コンパイル使用メモリ 165,052 KB
実行使用メモリ 27,116 KB
最終ジャッジ日時 2023-10-12 00:25:04
合計ジャッジ時間 4,829 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 22 ms
26,780 KB
testcase_01 AC 23 ms
26,896 KB
testcase_02 AC 23 ms
26,848 KB
testcase_03 AC 23 ms
26,976 KB
testcase_04 AC 23 ms
26,792 KB
testcase_05 AC 23 ms
26,900 KB
testcase_06 AC 25 ms
26,780 KB
testcase_07 AC 22 ms
26,832 KB
testcase_08 AC 23 ms
26,860 KB
testcase_09 AC 23 ms
26,788 KB
testcase_10 AC 23 ms
26,916 KB
testcase_11 AC 23 ms
26,780 KB
testcase_12 AC 22 ms
26,928 KB
testcase_13 AC 23 ms
26,780 KB
testcase_14 AC 22 ms
26,784 KB
testcase_15 AC 22 ms
26,856 KB
testcase_16 AC 23 ms
26,784 KB
testcase_17 AC 22 ms
26,848 KB
testcase_18 AC 22 ms
26,856 KB
testcase_19 AC 23 ms
26,772 KB
testcase_20 AC 22 ms
26,900 KB
testcase_21 AC 21 ms
26,800 KB
testcase_22 AC 23 ms
26,800 KB
testcase_23 AC 23 ms
26,852 KB
testcase_24 AC 23 ms
26,852 KB
testcase_25 AC 23 ms
26,984 KB
testcase_26 AC 23 ms
27,100 KB
testcase_27 AC 22 ms
26,856 KB
testcase_28 AC 23 ms
27,116 KB
testcase_29 AC 23 ms
26,980 KB
testcase_30 AC 23 ms
26,844 KB
testcase_31 AC 32 ms
27,044 KB
testcase_32 AC 22 ms
26,776 KB
testcase_33 AC 23 ms
26,916 KB
testcase_34 AC 22 ms
26,804 KB
testcase_35 AC 23 ms
26,852 KB
testcase_36 AC 22 ms
26,784 KB
testcase_37 AC 23 ms
26,780 KB
testcase_38 AC 22 ms
26,884 KB
testcase_39 AC 23 ms
26,796 KB
testcase_40 AC 25 ms
26,832 KB
testcase_41 AC 23 ms
26,848 KB
testcase_42 AC 24 ms
26,856 KB
testcase_43 AC 23 ms
26,996 KB
testcase_44 AC 24 ms
26,796 KB
testcase_45 AC 24 ms
26,776 KB
testcase_46 AC 33 ms
26,788 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;


const int MAX = 1000000;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

long long modpow(long long x, long long n) {
    long long ret = 1;
    while (n > 0) {
        if (n & 1) ret = (ret * x) % MOD;  
        x = (x * x) % MOD;
        n >>= 1;  
    }
    return ret;
}

int main(){
    COMinit();
    int n;
    cin >> n;
    ll ans = 0;
    for(int i=1;i<=n;i++){
        ans = (ans + (COM(n,i)*modpow(i,n-i))%MOD )%MOD;
    }
    cout << ans << endl;
    return 0;
}
0