結果

問題 No.573 a^2[i] = a[i]
ユーザー face4face4
提出日時 2019-02-03 14:51:54
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 59 ms / 2,000 ms
コード長 904 bytes
コンパイル時間 644 ms
コンパイル使用メモリ 70,704 KB
実行使用メモリ 6,452 KB
最終ジャッジ日時 2023-08-22 13:34:32
合計ジャッジ時間 3,339 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
6,328 KB
testcase_01 AC 5 ms
6,144 KB
testcase_02 AC 5 ms
6,308 KB
testcase_03 AC 5 ms
6,300 KB
testcase_04 AC 5 ms
6,260 KB
testcase_05 AC 5 ms
6,300 KB
testcase_06 AC 5 ms
6,308 KB
testcase_07 AC 5 ms
6,248 KB
testcase_08 AC 5 ms
6,188 KB
testcase_09 AC 5 ms
6,128 KB
testcase_10 AC 5 ms
6,196 KB
testcase_11 AC 5 ms
6,176 KB
testcase_12 AC 5 ms
6,308 KB
testcase_13 AC 5 ms
6,244 KB
testcase_14 AC 5 ms
6,144 KB
testcase_15 AC 5 ms
6,204 KB
testcase_16 AC 5 ms
6,196 KB
testcase_17 AC 5 ms
6,196 KB
testcase_18 AC 5 ms
6,192 KB
testcase_19 AC 5 ms
6,148 KB
testcase_20 AC 5 ms
6,276 KB
testcase_21 AC 5 ms
6,252 KB
testcase_22 AC 5 ms
6,328 KB
testcase_23 AC 5 ms
6,244 KB
testcase_24 AC 5 ms
6,128 KB
testcase_25 AC 5 ms
6,328 KB
testcase_26 AC 5 ms
6,240 KB
testcase_27 AC 5 ms
6,252 KB
testcase_28 AC 5 ms
6,192 KB
testcase_29 AC 5 ms
6,132 KB
testcase_30 AC 5 ms
6,292 KB
testcase_31 AC 5 ms
6,244 KB
testcase_32 AC 5 ms
6,132 KB
testcase_33 AC 5 ms
6,184 KB
testcase_34 AC 5 ms
6,132 KB
testcase_35 AC 5 ms
6,140 KB
testcase_36 AC 5 ms
6,132 KB
testcase_37 AC 5 ms
6,184 KB
testcase_38 AC 5 ms
6,132 KB
testcase_39 AC 5 ms
6,260 KB
testcase_40 AC 5 ms
6,180 KB
testcase_41 AC 5 ms
6,248 KB
testcase_42 AC 6 ms
6,200 KB
testcase_43 AC 6 ms
6,452 KB
testcase_44 AC 7 ms
6,132 KB
testcase_45 AC 9 ms
6,296 KB
testcase_46 AC 59 ms
6,328 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
using namespace std;

typedef long long ll;
const ll mod = 1e9 + 7;

ll modpow(ll a, ll b, ll p = 1e9+7){
    if(b == 0)  return 1;
    
    if(b % 2 == 0){
        ll d = modpow(a, b/2, p);
        return (d*d) % p;
    }else{
        return (a%p * modpow(a, b-1, p)) % p;
    }
}

int main(){
    vector<ll> fact(100001), inv(100001);
    fact[0] = 1;
    for(ll i = 1; i <= 100000; i++){
        fact[i] = (fact[i-1] * i)%mod;
    }
    inv[100000] = modpow(fact[100000], mod-2, mod);
    for(ll i = 99999; i >= 0; i--){
        inv[i] = (inv[i+1] * (i+1))%mod;
    }

    int n;
    cin >> n;

    auto ncm = [=](ll n, ll m) -> ll{
        return ((fact[n]*inv[m])%mod*inv[n-m])%mod;
    };

    ll ans = 0;
    for(int i = 1; i <= n; i++){
        ans += (ncm(n,i)*modpow(i, n-i, mod))%mod;
        ans %= mod;
    }

    cout << ans << endl;
    
    return 0;
}
0