結果

問題 No.16 累乗の加算
ユーザー こるこる
提出日時 2017-02-17 09:37:40
言語 Java21
(openjdk 21)
結果
AC  
実行時間 46 ms / 5,000 ms
コード長 1,068 bytes
コンパイル時間 4,394 ms
コンパイル使用メモリ 74,000 KB
実行使用メモリ 49,440 KB
最終ジャッジ日時 2023-09-08 12:05:44
合計ジャッジ時間 3,823 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
49,428 KB
testcase_01 AC 44 ms
49,132 KB
testcase_02 AC 46 ms
49,140 KB
testcase_03 AC 46 ms
49,072 KB
testcase_04 AC 44 ms
49,308 KB
testcase_05 AC 45 ms
49,332 KB
testcase_06 AC 45 ms
49,440 KB
testcase_07 AC 45 ms
49,060 KB
testcase_08 AC 46 ms
49,076 KB
testcase_09 AC 46 ms
49,140 KB
testcase_10 AC 45 ms
48,968 KB
testcase_11 AC 44 ms
48,980 KB
testcase_12 AC 45 ms
49,072 KB
testcase_13 AC 45 ms
49,344 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.io.*;

public class Main {
    
    static int mod=1000003;
    
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        int x=Integer.parseInt(st.nextToken());
        int n=Integer.parseInt(st.nextToken());
        int[] a=new int[n];
        st=new StringTokenizer(br.readLine());
        for(int i=0;i<n;i++){ a[i]=Integer.parseInt(st.nextToken()); }
        long sum=0;
        for(int i=0;i<n;i++){
            //System.out.println(x+"^"+a[i]+"="+pow(x,a[i]));
            sum=(sum+pow(x,a[i]))%mod;
            //System.out.println(sum);
        }System.out.println(sum%mod);
    }
    
    static long pow(long x,int n){
        //System.out.println(x+" "+n);
        x%=mod;
        if(n==1){ return x; }
        if(n==0){ return 1; }
        if(n%2==0){
            return pow(x*x,n/2)%mod;
        }else{
            return (pow(x,n-1)*x)%mod;
        }
    }

}
0