結果

問題 No.573 a^2[i] = a[i]
ユーザー mogurockermogurocker
提出日時 2017-10-24 18:56:53
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 43 ms / 2,000 ms
コード長 1,161 bytes
コンパイル時間 1,078 ms
コンパイル使用メモリ 158,640 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-05-01 13:10:23
合計ジャッジ時間 2,744 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
6,816 KB
testcase_01 AC 6 ms
6,940 KB
testcase_02 AC 7 ms
6,944 KB
testcase_03 AC 6 ms
6,940 KB
testcase_04 AC 7 ms
6,944 KB
testcase_05 AC 7 ms
6,940 KB
testcase_06 AC 7 ms
6,940 KB
testcase_07 AC 6 ms
6,940 KB
testcase_08 AC 7 ms
6,944 KB
testcase_09 AC 7 ms
6,944 KB
testcase_10 AC 7 ms
6,940 KB
testcase_11 AC 6 ms
6,944 KB
testcase_12 AC 8 ms
6,940 KB
testcase_13 AC 7 ms
6,944 KB
testcase_14 AC 7 ms
6,940 KB
testcase_15 AC 7 ms
6,940 KB
testcase_16 AC 8 ms
6,944 KB
testcase_17 AC 7 ms
6,940 KB
testcase_18 AC 8 ms
6,940 KB
testcase_19 AC 7 ms
6,944 KB
testcase_20 AC 8 ms
6,940 KB
testcase_21 AC 7 ms
6,944 KB
testcase_22 AC 7 ms
6,940 KB
testcase_23 AC 7 ms
6,940 KB
testcase_24 AC 7 ms
6,940 KB
testcase_25 AC 7 ms
6,948 KB
testcase_26 AC 7 ms
6,940 KB
testcase_27 AC 7 ms
6,940 KB
testcase_28 AC 7 ms
6,944 KB
testcase_29 AC 8 ms
6,940 KB
testcase_30 AC 8 ms
6,944 KB
testcase_31 AC 7 ms
6,944 KB
testcase_32 AC 7 ms
6,940 KB
testcase_33 AC 7 ms
6,944 KB
testcase_34 AC 7 ms
6,944 KB
testcase_35 AC 8 ms
6,940 KB
testcase_36 AC 8 ms
6,940 KB
testcase_37 AC 7 ms
6,944 KB
testcase_38 AC 8 ms
6,944 KB
testcase_39 AC 8 ms
6,944 KB
testcase_40 AC 8 ms
6,944 KB
testcase_41 AC 8 ms
6,944 KB
testcase_42 AC 9 ms
6,944 KB
testcase_43 AC 9 ms
6,944 KB
testcase_44 AC 8 ms
6,944 KB
testcase_45 AC 10 ms
6,940 KB
testcase_46 AC 43 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define FORR(x, arr) for(auto& x:arr)
#define ITR(x, c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;
typedef pair<int, int> P;

ll MOD=1e9+7;
const int NUM_=100005;
static ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1];
ll n;

ll mod_pow(ll x, ll n) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % MOD;
		x = x * x % MOD;
		n >>= 1;
	}
	return res;
}

ll nck(ll N_, ll K_) {
	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(K_<0 || K_>N_) return 0;
	return factr[K_]*fact[N_]%MOD*factr[N_-K_]%MOD;
}

int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	cin >> n;
	ll ret = 0;
	for (ll k = 1; k <= n; k++) {
		ll x = nck(n, k) * mod_pow(k, n-k) % MOD;
		ret = (ret + x) % MOD;
	}
	cout << ret << endl;
	return 0;
}
0