結果

問題 No.573 a^2[i] = a[i]
ユーザー polyomino_24polyomino_24
提出日時 2018-10-02 23:20:26
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 61 ms / 2,000 ms
コード長 928 bytes
コンパイル時間 409 ms
コンパイル使用メモリ 52,292 KB
実行使用メモリ 12,976 KB
最終ジャッジ日時 2023-08-02 14:28:44
合計ジャッジ時間 3,282 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
12,664 KB
testcase_01 AC 26 ms
12,660 KB
testcase_02 AC 26 ms
12,788 KB
testcase_03 AC 26 ms
12,840 KB
testcase_04 AC 26 ms
12,724 KB
testcase_05 AC 26 ms
12,812 KB
testcase_06 AC 26 ms
12,864 KB
testcase_07 AC 26 ms
12,652 KB
testcase_08 AC 25 ms
12,724 KB
testcase_09 AC 26 ms
12,972 KB
testcase_10 AC 26 ms
12,724 KB
testcase_11 AC 26 ms
12,776 KB
testcase_12 AC 26 ms
12,652 KB
testcase_13 AC 27 ms
12,656 KB
testcase_14 AC 26 ms
12,832 KB
testcase_15 AC 26 ms
12,864 KB
testcase_16 AC 26 ms
12,656 KB
testcase_17 AC 26 ms
12,724 KB
testcase_18 AC 26 ms
12,716 KB
testcase_19 AC 27 ms
12,644 KB
testcase_20 AC 26 ms
12,728 KB
testcase_21 AC 27 ms
12,724 KB
testcase_22 AC 26 ms
12,916 KB
testcase_23 AC 25 ms
12,644 KB
testcase_24 AC 26 ms
12,660 KB
testcase_25 AC 26 ms
12,788 KB
testcase_26 AC 26 ms
12,652 KB
testcase_27 AC 26 ms
12,724 KB
testcase_28 AC 26 ms
12,724 KB
testcase_29 AC 26 ms
12,736 KB
testcase_30 AC 26 ms
12,772 KB
testcase_31 AC 26 ms
12,656 KB
testcase_32 AC 26 ms
12,724 KB
testcase_33 AC 26 ms
12,976 KB
testcase_34 AC 26 ms
12,656 KB
testcase_35 AC 27 ms
12,716 KB
testcase_36 AC 26 ms
12,864 KB
testcase_37 AC 26 ms
12,652 KB
testcase_38 AC 26 ms
12,656 KB
testcase_39 AC 26 ms
12,652 KB
testcase_40 AC 26 ms
12,788 KB
testcase_41 AC 27 ms
12,640 KB
testcase_42 AC 27 ms
12,712 KB
testcase_43 AC 27 ms
12,720 KB
testcase_44 AC 27 ms
12,852 KB
testcase_45 AC 29 ms
12,732 KB
testcase_46 AC 61 ms
12,652 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;
using ll = long long;
ll mod=1000000007;
ll mod_pow(ll a,ll b){//a^b
    ll ans = 1;
    while(b!=0){
        if(b%2==0){
            b = b/2;
            a = (a*a)%mod;
        }
        else{
            ans = (ans *a)%mod;
            b--;
        }
    }
    return ans;
}
ll combi(ll N_, ll C_) {
    const int NUM_=400001;
    static ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1];
    if (fact[0]==0) {
        inv[1]=fact[0]=factr[0]=1;
        for (int i=2;i<=NUM_;++i) inv[i] = inv[mod % i] * (mod - mod / i) % mod;
        for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%mod, factr[i]=factr[i-1]*inv[i]%mod;
    }
    if(C_<0 || C_>N_) return 0;
    return factr[C_]*fact[N_]%mod*factr[N_-C_]%mod;
}

int main(){
    int n;
    cin >> n;
    ll ans = 0;
    for(int i = 1; i <= n; i++){
        ans += combi(n,i) * mod_pow(i,n-i);
        ans %= mod;
    }
    cout << ans << endl;
}
0