結果

問題 No.16 累乗の加算
ユーザー Mcpu3
提出日時 2018-09-01 11:39:29
言語 C
(gcc 13.3.0)
結果
AC  
実行時間 1 ms / 5,000 ms
コード長 352 bytes
コンパイル時間 147 ms
コンパイル使用メモリ 30,848 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-09-15 08:51:10
合計ジャッジ時間 723 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

long p(long x,long n)
{
    long r;
    if(1>n)return 1;
    r=p(x*x%1000003,n/2);
    if(n%2)r=r*x%1000003;
    return r;
}

int main(void)
{
    long x,n,a,s=0,i;
    scanf("%ld%ld",&x,&n);
    for(i=0;i<n;i++){
        scanf("%ld",&a);
        s=(s+p(x,a))%1000003;
    }
    printf("%ld",s);
    return 0;
}
0