結果

問題 No.1126 SUM
ユーザー forest3forest3
提出日時 2020-07-25 10:18:19
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 20 ms / 1,000 ms
コード長 680 bytes
コンパイル時間 2,092 ms
コンパイル使用メモリ 166,888 KB
実行使用メモリ 4,692 KB
最終ジャッジ日時 2023-09-09 05:54:21
合計ジャッジ時間 4,422 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
4,380 KB
testcase_01 AC 19 ms
4,564 KB
testcase_02 AC 9 ms
4,380 KB
testcase_03 AC 6 ms
4,380 KB
testcase_04 AC 19 ms
4,608 KB
testcase_05 AC 16 ms
4,380 KB
testcase_06 AC 10 ms
4,376 KB
testcase_07 AC 14 ms
4,376 KB
testcase_08 AC 15 ms
4,380 KB
testcase_09 AC 17 ms
4,376 KB
testcase_10 AC 16 ms
4,384 KB
testcase_11 AC 14 ms
4,380 KB
testcase_12 AC 17 ms
4,380 KB
testcase_13 AC 10 ms
4,380 KB
testcase_14 AC 13 ms
4,380 KB
testcase_15 AC 11 ms
4,376 KB
testcase_16 AC 17 ms
4,476 KB
testcase_17 AC 10 ms
4,376 KB
testcase_18 AC 14 ms
4,380 KB
testcase_19 AC 19 ms
4,692 KB
testcase_20 AC 10 ms
4,380 KB
testcase_21 AC 18 ms
4,380 KB
testcase_22 AC 13 ms
4,376 KB
testcase_23 AC 18 ms
4,380 KB
testcase_24 AC 13 ms
4,376 KB
testcase_25 AC 20 ms
4,568 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

long long power( long long x, int n, int m )
{
	long long res = 1;
	while( n > 0 ) {
		if( n %  2 ) res = res * x % m;
		x = x * x % m;
		n /= 2;
	}
	return res;
}

int main()
{
	long long N, M;
	cin >> N >> M;

	const int MOD = 1000000000 + 7;
	vector<long long> fac( M + 1 );
	vector<long long> ifac( M + 1 );
	fac[0] = 1;
	ifac[0] = power( 1, MOD - 2, MOD );
	for( int i = 1; i <= M; i++ ) {
		fac[i] = fac[i - 1] * i;
		fac[i] %= MOD;
		ifac[i] = power( fac[i], MOD - 2, MOD );
	}
	long long ans = 0;
	for( int i = N; i <= M; i++ ) {
		ans += fac[i] * ifac[N] % MOD * ifac[i - N] % MOD;
		ans %= MOD;
	}

	cout << ans << endl;
}
0