結果

問題 No.573 a^2[i] = a[i]
ユーザー shotoyooshotoyoo
提出日時 2021-05-27 00:01:07
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 90 ms / 2,000 ms
コード長 1,122 bytes
コンパイル時間 154 ms
コンパイル使用メモリ 82,356 KB
実行使用メモリ 69,020 KB
最終ジャッジ日時 2024-04-23 17:14:57
合計ジャッジ時間 3,240 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
53,436 KB
testcase_01 AC 34 ms
53,620 KB
testcase_02 AC 34 ms
53,184 KB
testcase_03 AC 34 ms
53,240 KB
testcase_04 AC 34 ms
52,460 KB
testcase_05 AC 34 ms
53,620 KB
testcase_06 AC 33 ms
53,504 KB
testcase_07 AC 34 ms
52,580 KB
testcase_08 AC 33 ms
54,088 KB
testcase_09 AC 33 ms
54,028 KB
testcase_10 AC 33 ms
52,124 KB
testcase_11 AC 34 ms
52,620 KB
testcase_12 AC 33 ms
53,196 KB
testcase_13 AC 34 ms
53,428 KB
testcase_14 AC 34 ms
52,496 KB
testcase_15 AC 34 ms
52,656 KB
testcase_16 AC 34 ms
53,556 KB
testcase_17 AC 34 ms
52,464 KB
testcase_18 AC 36 ms
53,680 KB
testcase_19 AC 35 ms
52,928 KB
testcase_20 AC 35 ms
52,832 KB
testcase_21 AC 34 ms
52,872 KB
testcase_22 AC 34 ms
52,340 KB
testcase_23 AC 33 ms
52,804 KB
testcase_24 AC 35 ms
52,892 KB
testcase_25 AC 36 ms
52,980 KB
testcase_26 AC 33 ms
52,820 KB
testcase_27 AC 33 ms
53,872 KB
testcase_28 AC 32 ms
52,756 KB
testcase_29 AC 33 ms
53,616 KB
testcase_30 AC 33 ms
52,964 KB
testcase_31 AC 33 ms
53,024 KB
testcase_32 AC 33 ms
52,860 KB
testcase_33 AC 35 ms
53,288 KB
testcase_34 AC 36 ms
54,356 KB
testcase_35 AC 36 ms
53,372 KB
testcase_36 AC 37 ms
54,436 KB
testcase_37 AC 36 ms
53,628 KB
testcase_38 AC 37 ms
53,972 KB
testcase_39 AC 42 ms
61,936 KB
testcase_40 AC 43 ms
61,112 KB
testcase_41 AC 45 ms
61,460 KB
testcase_42 AC 47 ms
62,952 KB
testcase_43 AC 47 ms
63,140 KB
testcase_44 AC 49 ms
63,096 KB
testcase_45 AC 49 ms
64,300 KB
testcase_46 AC 90 ms
69,020 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda : sys.stdin.readline().rstrip()

sys.setrecursionlimit(2*10**5+10)
write = lambda x: sys.stdout.write(x+"\n")
debug = lambda x: sys.stderr.write(x+"\n")
writef = lambda x: print("{:.12f}".format(x))


n = int(input())
M = 10**9+7
### 素数の逆元とCombination

M = 10**9+7 # 出力の制限
# M = 998244353
N = n+10 # 必要なテーブルサイズ
g1 = [0] * (N+1) # 元テーブル
g2 = [0] * (N+1) #逆元テーブル
inverse = [0] * (N+1) #逆元テーブル計算用テーブル
g1[0] = g1[1] = g2[0] = g2[1] = 1
inverse[0], inverse[1] = [0, 1] 
for i in range( 2, N + 1 ):
    g1[i] = ( g1[i-1] * i ) % M 
    inverse[i] = ( -inverse[M % i] * (M//i) ) % M # ai+b==0 mod M <=> i==-b*a^(-1) <=> i^(-1)==-b^(-1)*aより
    g2[i] = (g2[i-1] * inverse[i]) % M 
def cmb(n, r, M=M):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return ((g1[n] * g2[r] % M) * g2[n-r]) % M
def perm(n, r, M=M):
    if (r<0 or r>n):
        return 0
    return (g1[n] * g2[n-r]) % M

ans = 0
for k in range(1, n+1):
    v = pow(k, n-k, M) * cmb(n, k) % M
    ans += v
    ans %= M
print(ans%M)
0