結果

問題 No.573 a^2[i] = a[i]
ユーザー ats5515ats5515
提出日時 2017-10-06 23:27:17
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 14 ms / 2,000 ms
コード長 1,464 bytes
コンパイル時間 709 ms
コンパイル使用メモリ 77,272 KB
実行使用メモリ 5,260 KB
最終ジャッジ日時 2023-08-10 17:26:53
合計ジャッジ時間 2,327 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
5,004 KB
testcase_01 AC 3 ms
4,936 KB
testcase_02 AC 4 ms
4,928 KB
testcase_03 AC 4 ms
5,008 KB
testcase_04 AC 4 ms
4,988 KB
testcase_05 AC 3 ms
4,924 KB
testcase_06 AC 4 ms
4,916 KB
testcase_07 AC 3 ms
5,040 KB
testcase_08 AC 4 ms
4,916 KB
testcase_09 AC 4 ms
4,916 KB
testcase_10 AC 4 ms
4,924 KB
testcase_11 AC 3 ms
5,204 KB
testcase_12 AC 4 ms
4,976 KB
testcase_13 AC 3 ms
5,068 KB
testcase_14 AC 4 ms
5,120 KB
testcase_15 AC 4 ms
4,936 KB
testcase_16 AC 4 ms
4,928 KB
testcase_17 AC 3 ms
4,912 KB
testcase_18 AC 3 ms
4,920 KB
testcase_19 AC 3 ms
5,000 KB
testcase_20 AC 4 ms
4,996 KB
testcase_21 AC 3 ms
4,928 KB
testcase_22 AC 4 ms
4,996 KB
testcase_23 AC 4 ms
5,072 KB
testcase_24 AC 4 ms
4,928 KB
testcase_25 AC 4 ms
4,920 KB
testcase_26 AC 4 ms
5,000 KB
testcase_27 AC 4 ms
4,924 KB
testcase_28 AC 4 ms
5,000 KB
testcase_29 AC 4 ms
5,064 KB
testcase_30 AC 4 ms
4,996 KB
testcase_31 AC 4 ms
4,916 KB
testcase_32 AC 4 ms
4,932 KB
testcase_33 AC 4 ms
5,256 KB
testcase_34 AC 4 ms
5,040 KB
testcase_35 AC 4 ms
5,260 KB
testcase_36 AC 3 ms
5,212 KB
testcase_37 AC 4 ms
5,244 KB
testcase_38 AC 4 ms
5,204 KB
testcase_39 AC 3 ms
5,256 KB
testcase_40 AC 4 ms
4,976 KB
testcase_41 AC 4 ms
4,984 KB
testcase_42 AC 4 ms
5,120 KB
testcase_43 AC 4 ms
5,064 KB
testcase_44 AC 4 ms
5,064 KB
testcase_45 AC 5 ms
5,040 KB
testcase_46 AC 14 ms
5,000 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
int t;
template <typename Int, Int MOD, int N>
struct comb_util {
	std::array<Int, N + 1> fc, ifc;

	comb_util() {
		fc[0] = 1;
		for (int i = 1; i <= N; i++) fc[i] = fc[i - 1] * i % MOD;
		ifc[N] = inv(fc[N]);
		for (int i = N - 1; i >= 0; i--) ifc[i] = ifc[i + 1] * (i + 1) % MOD;
	}

	Int fact(Int n) { return fc[n]; }

	Int inv_fact(Int n) { return ifc[n]; }

	Int inv(Int n) { return pow(n, MOD - 2); }

	Int pow(Int n, Int a) {
		Int res = 1, exp = n;
		for (; a; a /= 2) {
			if (a & 1) res = res * exp % MOD;
			exp = exp * exp % MOD;
		}
		return res;
	}

	Int perm(Int n, Int r) {
		if (r < 0 || n < r)
			return 0;
		else
			return fc[n] * ifc[n - r] % MOD;
	}

	Int binom(Int n, Int r) {
		if (n < 0 || r < 0 || n < r) return 0;
		return fc[n] * ifc[r] % MOD * ifc[n - r] % MOD;
	}

	Int homo(Int n, Int r) {
		if (n < 0 || r < 0) return 0;
		return r == 0 ? 1 : binom(n + r - 1, r);
	}
};

using comb = comb_util<long long, 1000000007, 100005>;

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	comb cb;
	int N;
	cin >> N;
	int k;
	int res = 0;
	for (int i = 1; i <= N; i++) {
		k = cb.binom(N, i);
		k = (k*cb.pow(N - i, i)) % MOD;
		res = (res + k) % MOD;
	}


	cout << (res+1) % MOD << endl;
}
0