結果

問題 No.16 累乗の加算
ユーザー kwnwsdnckwnwsdnc
提出日時 2018-04-24 21:20:28
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 17 ms / 5,000 ms
コード長 576 bytes
コンパイル時間 351 ms
コンパイル使用メモリ 11,000 KB
実行使用メモリ 7,908 KB
最終ジャッジ日時 2023-09-09 23:58:33
合計ジャッジ時間 1,261 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,816 KB
testcase_01 AC 16 ms
7,908 KB
testcase_02 AC 17 ms
7,804 KB
testcase_03 AC 16 ms
7,716 KB
testcase_04 AC 16 ms
7,776 KB
testcase_05 AC 15 ms
7,908 KB
testcase_06 AC 15 ms
7,716 KB
testcase_07 AC 15 ms
7,820 KB
testcase_08 AC 16 ms
7,908 KB
testcase_09 AC 16 ms
7,864 KB
testcase_10 AC 16 ms
7,716 KB
testcase_11 AC 15 ms
7,788 KB
testcase_12 AC 15 ms
7,904 KB
testcase_13 AC 16 ms
7,792 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def power(x,n):
    p=[]
    X=x
    if n==0:
        return 1
    if n==1:
        return x
    
    while n!=1:
        if n%2==0:
            n=n/2
            p.append(2)
        else:
            n=n-1
            p.append(1)
            
    l=len(p)
    for i in range(l):
        if p[(l-1)-i]==2:
            X=X**2
        else:
            X*=x
        if X>N:
            X=X%N
        
    return X%N
    
num=list(map(int,input().split()))
a=list(map(int,input().split()))
N=1000003
total=0

for i in range(num[1]):
    total+=power(num[0],a[i])

print(total%N)
0