結果

問題 No.16 累乗の加算
ユーザー momoyuumomoyuu
提出日時 2022-03-22 03:21:33
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,394 bytes
コンパイル時間 348 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 261,092 KB
最終ジャッジ日時 2024-04-18 00:24:19
合計ジャッジ時間 7,045 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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 += pow(x,a[i])
    print(count)

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