結果
| 問題 | 
                            No.16 累乗の加算
                             | 
                    
| コンテスト | |
| ユーザー | 
                             mits58
                         | 
                    
| 提出日時 | 2016-07-02 21:38:12 | 
| 言語 | Java  (openjdk 23)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 145 ms / 5,000 ms | 
| コード長 | 516 bytes | 
| コンパイル時間 | 2,196 ms | 
| コンパイル使用メモリ | 74,932 KB | 
| 実行使用メモリ | 41,432 KB | 
| 最終ジャッジ日時 | 2024-06-26 05:15:16 | 
| 合計ジャッジ時間 | 4,917 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 14 | 
ソースコード
import java.util.Scanner;
public class Main{
	static long mod=1000003;
	static long pow(long a,long x,long m){
		if(x==0) return 1;
		else if(x%2==0) return pow((a*a)%m,x/2,m)%m;
		else return (a*pow((a*a)%m,x/2,m))%m;
	}
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		while(sc.hasNext()){
			long x=sc.nextLong();
			int n=sc.nextInt();
			long ans=0;
			for(int i=0;i<n;i++){
				long a=sc.nextLong();
				ans+=pow(x,a,mod);
				ans%=mod;
			}
			System.out.println(ans);
		}
	}
}
            
            
            
        
            
mits58