結果

問題 No.16 累乗の加算
ユーザー kohaku_kohakukohaku_kohaku
提出日時 2016-11-17 23:27:47
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 653 bytes
コンパイル時間 2,272 ms
コンパイル使用メモリ 72,020 KB
実行使用メモリ 57,952 KB
最終ジャッジ日時 2023-08-17 08:13:16
合計ジャッジ時間 4,818 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
55,728 KB
testcase_01 AC 125 ms
53,528 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 124 ms
55,936 KB
testcase_12 WA -
testcase_13 AC 130 ms
55,864 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 sum=0;
        for(int i=0; i<N; i++){
            long a = sc.nextInt();
            sum+=pow(x,a);
        }
        System.out.println(sum);
    }
    static long pow(long x, long n){
        long m = 1000003;
        x%=m;
        if(n==0){
            return 1;
        }else if(n%2==1){
            long r = pow(x,n-1)%m;
            return x*r%m;
        }else{
            long r = pow(x,n/2)%m;
            return r*r%m;
        }
    }
}
0