結果

問題 No.573 a^2[i] = a[i]
ユーザー mogurockermogurocker
提出日時 2017-10-24 18:56:53
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 37 ms / 2,000 ms
コード長 1,161 bytes
コンパイル時間 979 ms
コンパイル使用メモリ 144,536 KB
実行使用メモリ 6,044 KB
最終ジャッジ日時 2023-08-13 23:34:55
合計ジャッジ時間 3,526 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
5,724 KB
testcase_01 AC 6 ms
5,768 KB
testcase_02 AC 6 ms
5,724 KB
testcase_03 AC 6 ms
5,708 KB
testcase_04 AC 7 ms
5,764 KB
testcase_05 AC 6 ms
5,700 KB
testcase_06 AC 6 ms
5,728 KB
testcase_07 AC 6 ms
5,768 KB
testcase_08 AC 6 ms
5,764 KB
testcase_09 AC 6 ms
5,732 KB
testcase_10 AC 6 ms
5,768 KB
testcase_11 AC 7 ms
5,724 KB
testcase_12 AC 6 ms
5,984 KB
testcase_13 AC 6 ms
5,764 KB
testcase_14 AC 6 ms
5,772 KB
testcase_15 AC 7 ms
5,976 KB
testcase_16 AC 6 ms
5,724 KB
testcase_17 AC 6 ms
5,700 KB
testcase_18 AC 7 ms
5,760 KB
testcase_19 AC 7 ms
5,712 KB
testcase_20 AC 7 ms
5,732 KB
testcase_21 AC 7 ms
5,836 KB
testcase_22 AC 6 ms
5,764 KB
testcase_23 AC 6 ms
6,008 KB
testcase_24 AC 6 ms
5,772 KB
testcase_25 AC 6 ms
5,984 KB
testcase_26 AC 6 ms
5,776 KB
testcase_27 AC 7 ms
5,720 KB
testcase_28 AC 6 ms
5,704 KB
testcase_29 AC 7 ms
6,008 KB
testcase_30 AC 7 ms
5,736 KB
testcase_31 AC 7 ms
5,728 KB
testcase_32 AC 7 ms
5,768 KB
testcase_33 AC 7 ms
5,880 KB
testcase_34 AC 6 ms
5,884 KB
testcase_35 AC 6 ms
5,716 KB
testcase_36 AC 7 ms
5,724 KB
testcase_37 AC 7 ms
5,776 KB
testcase_38 AC 6 ms
6,044 KB
testcase_39 AC 7 ms
5,756 KB
testcase_40 AC 7 ms
5,716 KB
testcase_41 AC 7 ms
5,716 KB
testcase_42 AC 7 ms
5,704 KB
testcase_43 AC 7 ms
5,760 KB
testcase_44 AC 8 ms
5,728 KB
testcase_45 AC 9 ms
5,904 KB
testcase_46 AC 37 ms
5,764 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