結果

問題 No.391 CODING WAR
ユーザー tomeruntomerun
提出日時 2016-07-17 22:03:42
言語 Ruby
(3.3.0)
結果
AC  
実行時間 1,009 ms / 2,000 ms
コード長 353 bytes
コンパイル時間 102 ms
コンパイル使用メモリ 11,244 KB
実行使用メモリ 15,428 KB
最終ジャッジ日時 2023-08-27 01:41:43
合計ジャッジ時間 9,203 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
15,156 KB
testcase_01 AC 75 ms
15,128 KB
testcase_02 AC 75 ms
15,312 KB
testcase_03 AC 73 ms
15,016 KB
testcase_04 AC 75 ms
15,032 KB
testcase_05 AC 79 ms
15,116 KB
testcase_06 AC 77 ms
15,152 KB
testcase_07 AC 78 ms
15,088 KB
testcase_08 AC 78 ms
15,316 KB
testcase_09 AC 1,009 ms
15,428 KB
testcase_10 AC 952 ms
15,320 KB
testcase_11 AC 726 ms
15,168 KB
testcase_12 AC 73 ms
15,136 KB
testcase_13 AC 929 ms
15,116 KB
testcase_14 AC 750 ms
15,236 KB
testcase_15 AC 845 ms
15,260 KB
testcase_16 AC 531 ms
15,332 KB
testcase_17 AC 623 ms
15,120 KB
testcase_18 AC 447 ms
15,396 KB
testcase_19 AC 443 ms
15,240 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

MOD = 1_000_000_007
n,m = gets.split.map(&:to_i)

def powmod(v, p)
	return 1 if p == 0
	return v if p == 1
	ret = powmod(v, p / 2)
	ret *= ret
	ret %= MOD
	p % 2 == 1 ? ret * v % MOD : ret
end

ans = 0
sgn = 1
comb = 1
m.downto(1) { |i|
	ans += sgn * powmod(i, n) * comb
	sgn *= -1
	comb *= i * powmod(m + 1 - i, MOD - 2)
	comb %= MOD
}
puts ans % MOD

0