結果

問題 No.573 a^2[i] = a[i]
ユーザー kohei2019kohei2019
提出日時 2022-02-11 14:39:52
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 411 ms / 2,000 ms
コード長 1,204 bytes
コンパイル時間 353 ms
コンパイル使用メモリ 86,456 KB
実行使用メモリ 95,348 KB
最終ジャッジ日時 2023-09-09 16:02:29
合計ジャッジ時間 6,943 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
70,612 KB
testcase_01 AC 75 ms
70,984 KB
testcase_02 AC 76 ms
70,884 KB
testcase_03 AC 73 ms
70,892 KB
testcase_04 AC 73 ms
70,976 KB
testcase_05 AC 77 ms
70,888 KB
testcase_06 AC 76 ms
70,936 KB
testcase_07 AC 73 ms
71,076 KB
testcase_08 AC 72 ms
70,960 KB
testcase_09 AC 72 ms
70,608 KB
testcase_10 AC 73 ms
70,872 KB
testcase_11 AC 71 ms
70,972 KB
testcase_12 AC 72 ms
70,980 KB
testcase_13 AC 72 ms
71,124 KB
testcase_14 AC 75 ms
71,120 KB
testcase_15 AC 74 ms
70,612 KB
testcase_16 AC 74 ms
70,916 KB
testcase_17 AC 71 ms
70,888 KB
testcase_18 AC 72 ms
70,944 KB
testcase_19 AC 72 ms
70,760 KB
testcase_20 AC 73 ms
70,948 KB
testcase_21 AC 71 ms
70,892 KB
testcase_22 AC 73 ms
71,012 KB
testcase_23 AC 74 ms
70,936 KB
testcase_24 AC 73 ms
70,756 KB
testcase_25 AC 74 ms
70,968 KB
testcase_26 AC 74 ms
70,880 KB
testcase_27 AC 74 ms
71,000 KB
testcase_28 AC 76 ms
70,944 KB
testcase_29 AC 74 ms
70,612 KB
testcase_30 AC 73 ms
70,952 KB
testcase_31 AC 73 ms
70,876 KB
testcase_32 AC 80 ms
75,232 KB
testcase_33 AC 88 ms
75,324 KB
testcase_34 AC 97 ms
76,936 KB
testcase_35 AC 104 ms
76,944 KB
testcase_36 AC 101 ms
76,988 KB
testcase_37 AC 93 ms
76,444 KB
testcase_38 AC 89 ms
75,552 KB
testcase_39 AC 111 ms
77,924 KB
testcase_40 AC 104 ms
77,336 KB
testcase_41 AC 103 ms
77,788 KB
testcase_42 AC 105 ms
77,404 KB
testcase_43 AC 117 ms
77,520 KB
testcase_44 AC 131 ms
78,352 KB
testcase_45 AC 126 ms
77,888 KB
testcase_46 AC 411 ms
95,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class NCK:
    '''
    最大値 :N
    mod
    '''
    def __init__(self,N,mod):
        self.mod = mod
        self.N = N
        self.factmod = [1,1]
        for i in range(2,self.N+1):
            self.factmod.append((self.factmod[-1]*i)%self.mod)

        self.inv = [0,1]
        for i in range(2, N + 1):
            self.inv.append((-self.inv[self.mod % i] * (self.mod // i)) % self.mod)

        self.invfact = [1,1]
        for i in range(2, N + 1):
            self.invfact.append((self.invfact[-1]*self.inv[i])%self.mod)

    def nCk(self,a,b):
        if a < b:
            return 0
        return ((self.factmod[a]*self.invfact[b]%self.mod)*self.invfact[a-b])%self.mod
    
    def invnCk(self,a,b):
        return ((self.factmod[a-b]*self.invfact[a]%self.mod)*self.factmod[b])%self.mod
    
def modPow(a,n,mod):#繰り返し二乗法 a**n % mod
    if n==0:
        return 1
    if n==1:
        return a%mod
    if n & 1:
        return (a*modPow(a,n-1,mod)) % mod
    t = modPow(a,n>>1,mod)
    return (t*t)%mod

N = int(input())
# Σ(k=1,N) NCk*K**(N-K)
mod = 10**9+7

ans = 0
nck = NCK(N+1,mod)
for i in range(1,N+1):
    ans += nck.nCk(N,i)*modPow(i,N-i,mod)
    ans %= mod
print(ans)
0