結果

問題 No.391 CODING WAR
ユーザー atjh16atjh16
提出日時 2021-09-06 22:48:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 41 ms / 2,000 ms
コード長 656 bytes
コンパイル時間 1,747 ms
コンパイル使用メモリ 164,464 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-24 13:05:29
合計ジャッジ時間 3,180 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 41 ms
4,380 KB
testcase_10 AC 39 ms
4,384 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,384 KB
testcase_13 AC 37 ms
4,380 KB
testcase_14 AC 30 ms
4,384 KB
testcase_15 AC 33 ms
4,384 KB
testcase_16 AC 20 ms
4,384 KB
testcase_17 AC 24 ms
4,380 KB
testcase_18 AC 17 ms
4,384 KB
testcase_19 AC 17 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

long long n, m, ans = 0, w = 1, z = 1, y;
const long long M = 1e9 + 7;

long long powm(long long a, long long b) {
	long long u = 1, v = a;

	while (b > 0) {
		if (b & 1)
			u = u * v % M;

		b >>= 1;
		v = v * v % M;
	}

	return u;
}

int main()
{
	cin >> n >> m;

	if (m > n)
		cout << 0 << endl;
	else {
		if (m % 2 == 1)
			y = -1;
		else
			y = 1;

		for (int i = 1; i <= m; i++) {
			w = w * (m - i + 1) % M;
			z = z * i % M;
			y *= -1;

			if (i == m)
				ans = (ans + powm(i, n)) % M;
			else
				ans = (ans + M + w * powm(z, M - 2) % M * powm(i, n) % M * y) % M;			
		}

		cout << ans << endl;
	}
}
0