結果

問題 No.16 累乗の加算
コンテスト
ユーザー こる
提出日時 2017-02-17 09:37:40
言語 Java
(openjdk 25.0.2)
コンパイル:
javac -encoding UTF8 _filename_
実行:
java -ea -Xmx700m -Xss256M -DONLINE_JUDGE=true _class_
結果
AC  
実行時間 32 ms / 5,000 ms
コード長 1,068 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,691 ms
コンパイル使用メモリ 82,484 KB
実行使用メモリ 44,868 KB
最終ジャッジ日時 2026-03-12 19:47:52
合計ジャッジ時間 2,716 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 14
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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