結果

問題 No.16 累乗の加算
ユーザー momoyuumomoyuu
提出日時 2022-03-22 03:18:18
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,397 bytes
コンパイル時間 193 ms
コンパイル使用メモリ 82,460 KB
実行使用メモリ 61,964 KB
最終ジャッジ日時 2024-04-18 00:21:28
合計ジャッジ時間 1,377 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
52,224 KB
testcase_01 AC 37 ms
51,840 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 38 ms
51,968 KB
testcase_12 WA -
testcase_13 AC 37 ms
52,608 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class modint:
    def __init__(self,mod):
        self.mod = mod

    def plus(self,x,y):
        n = x + y
        n %= self.mod
        return n
    
    def times(self,x,y):
        return (x*y)%self.mod
    
    def pow(self,n,m):
        """
        n^m
        """

        l = len(bin(m)) - 2
        d = [n]

        for i in range(1,l):
            a = d[i-1]*d[i-1]
            a %= self.mod
            d.append(a)
        ans = 1
        for i in range(l):
            if m >> i & 1:
                ans *= d[i]
                ans %= self.mod
        return ans
    
    def combination(self,n,r):
        """
        nCrを計算。
        """

        a = 1 #n!
        b = 1 #(n-r)!
        c = 1 #r!
        for i in range(2,n+1):
            a *= i
            a %= self.mod
            if i == n-r:
                b = a
            if i == r:
                c = a
        b = self.inverse(b)
        c = self.inverse(c)
        a *= b
        a %= self.mod
        a *= c
        a %= self.mod
        return a
    
    def inverse(self,n):
        return self.pow(n,self.mod-2)

def main():
    import sys
    input = sys.stdin.readline
    x,N = map(int,input().split())
    a = list(map(int,input().split()))
    mod = 10**6+3
    mi = modint(mod)
    count = 0
    for i in range(N):
        count += mi.pow(x,a[i])
    print(count)

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