結果

問題 No.573 a^2[i] = a[i]
ユーザー 双六双六
提出日時 2020-08-10 06:04:29
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 118 ms / 2,000 ms
コード長 939 bytes
コンパイル時間 186 ms
コンパイル使用メモリ 82,576 KB
実行使用メモリ 74,240 KB
最終ジャッジ日時 2024-04-15 22:13:06
合計ジャッジ時間 3,785 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
54,144 KB
testcase_01 AC 45 ms
53,888 KB
testcase_02 AC 50 ms
53,788 KB
testcase_03 AC 48 ms
53,504 KB
testcase_04 AC 47 ms
54,144 KB
testcase_05 AC 47 ms
54,016 KB
testcase_06 AC 46 ms
54,016 KB
testcase_07 AC 46 ms
54,144 KB
testcase_08 AC 46 ms
53,760 KB
testcase_09 AC 46 ms
53,504 KB
testcase_10 AC 49 ms
54,144 KB
testcase_11 AC 47 ms
54,144 KB
testcase_12 AC 46 ms
54,272 KB
testcase_13 AC 46 ms
54,144 KB
testcase_14 AC 46 ms
53,760 KB
testcase_15 AC 45 ms
53,888 KB
testcase_16 AC 46 ms
54,016 KB
testcase_17 AC 46 ms
53,888 KB
testcase_18 AC 46 ms
53,760 KB
testcase_19 AC 46 ms
53,888 KB
testcase_20 AC 46 ms
53,876 KB
testcase_21 AC 47 ms
53,760 KB
testcase_22 AC 46 ms
53,760 KB
testcase_23 AC 47 ms
53,504 KB
testcase_24 AC 46 ms
53,504 KB
testcase_25 AC 46 ms
53,760 KB
testcase_26 AC 46 ms
54,016 KB
testcase_27 AC 48 ms
53,760 KB
testcase_28 AC 46 ms
53,888 KB
testcase_29 AC 46 ms
53,504 KB
testcase_30 AC 47 ms
54,144 KB
testcase_31 AC 46 ms
53,760 KB
testcase_32 AC 47 ms
53,632 KB
testcase_33 AC 47 ms
53,888 KB
testcase_34 AC 48 ms
54,272 KB
testcase_35 AC 48 ms
54,272 KB
testcase_36 AC 47 ms
54,144 KB
testcase_37 AC 48 ms
54,912 KB
testcase_38 AC 48 ms
54,144 KB
testcase_39 AC 59 ms
62,080 KB
testcase_40 AC 56 ms
61,952 KB
testcase_41 AC 56 ms
62,080 KB
testcase_42 AC 57 ms
62,464 KB
testcase_43 AC 57 ms
62,080 KB
testcase_44 AC 59 ms
62,336 KB
testcase_45 AC 60 ms
63,360 KB
testcase_46 AC 118 ms
74,240 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys; input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

def getlist():
	return list(map(int, input().split()))

class Combination(object):
	def __init__(self, N, con):
		self.fac = [0] * (N + 1)
		self.inv = [0] * (N + 1)
		self.finv = [0] * (N + 1)
		self.fac[0], self.fac[1] = 1, 1
		self.inv[1] = 1
		self.finv[0], self.finv[1] = 1, 1

		# 前計算
		for i in range(2, N + 1):
			self.fac[i] = self.fac[i - 1] * i % con
			self.inv[i] = self.inv[con % i] * (con - (con // i)) % con
			self.finv[i] = self.finv[i - 1] * self.inv[i] % con

	def com(self, N, k):
		return (self.fac[N] * self.finv[k] * self.finv[N - k]) % con

#処理内容
def main():
	N = int(input())
	C = Combination(N, con)
	ans = 0
	for i in range(1, N + 1):
		a = C.com(N, i) * pow(i, N - i, con)
		ans += a
		ans %= con

	print(ans)
	
if __name__ == '__main__':
	main()
0