結果

問題 No.16 累乗の加算
ユーザー shinshin
提出日時 2022-05-17 20:28:59
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,185 bytes
コンパイル時間 4,304 ms
コンパイル使用メモリ 75,012 KB
実行使用メモリ 51,148 KB
最終ジャッジ日時 2023-10-13 20:05:48
合計ジャッジ時間 6,077 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
49,128 KB
testcase_01 AC 44 ms
49,248 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 44 ms
49,296 KB
testcase_12 WA -
testcase_13 AC 50 ms
49,500 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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;

	}

}
0