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