結果
| 問題 | 
                            No.16 累乗の加算
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2022-05-17 20:28:59 | 
| 言語 | Java  (openjdk 23)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,185 bytes | 
| コンパイル時間 | 4,066 ms | 
| コンパイル使用メモリ | 78,484 KB | 
| 実行使用メモリ | 38,520 KB | 
| 最終ジャッジ日時 | 2024-09-15 15:48:57 | 
| 合計ジャッジ時間 | 5,912 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 4 WA * 10 | 
ソースコード
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
public class No16 {
	
	static long K = 1000003;
	public static void main(String[] args) throws IOException{
		//累乗の加算
		String[] text = readStr();
		Long x = Long.parseLong(text[0].split(" ")[0]) , a;
		int N = Integer.parseInt(text[0].split(" ")[1]);
		long sum = 0;
		
		for(int i = 0;i < N;i++) {
			a = Long.parseLong(text[1].split(" ")[i]);
			sum += div(x , a);
		}
		
		System.out.println(sum);
		
	}
		
	
	public static long div(long x , long a) {
		long ans , c = 1;
		
		if(x <= 1) {
			ans = x;
		}else {
			while((long)Math.pow(x, c) < K) c++;
			if(c > a) {
				ans = (long)Math.pow(x, a);
			}else {
				ans = div((long)Math.pow(x, c) % K , a / c) * div(x , a % c) % K;
			}
		}
		
		return ans;
	}
	
	public static String[] readStr() throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		ArrayList<String> list = new ArrayList<>();
		do {
			list.add(br.readLine());
		}while(br.ready());
		br.close();
		String[] text = new String[list.size()];
		list.toArray(text);
		return text;
	}
}