結果

問題 No.16 累乗の加算
ユーザー kohaku_kohakukohaku_kohaku
提出日時 2016-11-17 22:56:29
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 656 bytes
コンパイル時間 2,619 ms
コンパイル使用メモリ 71,452 KB
実行使用メモリ 57,860 KB
最終ジャッジ日時 2023-08-17 08:12:38
合計ジャッジ時間 5,474 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
55,724 KB
testcase_01 WA -
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 WA -
testcase_12 WA -
testcase_13 AC 131 ms
56,028 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long x = sc.nextLong();
        int N = sc.nextInt();
        long mod = 1000003;
        long sum=0;
        for(int i=0; i<N; i++){
            long a = sc.nextInt();
            sum+=pow(x,a,mod);
        }
        System.out.println(sum);
    }
    static long pow(long x, long n, long m){
        if(n==0){
            return 1;
        }else if(n%2==1){
            long r = x*pow(x*x,n/2,m)%m;
            return r;
        }else{
            long r = pow(x*x,n/2,m)%m;
            return r;
        }
    }
}
0