結果

問題 No.16 累乗の加算
ユーザー jp_stejp_ste
提出日時 2016-02-12 16:34:38
言語 Java21
(openjdk 21)
結果
AC  
実行時間 134 ms / 5,000 ms
コード長 553 bytes
コンパイル時間 2,033 ms
コンパイル使用メモリ 70,500 KB
実行使用メモリ 57,272 KB
最終ジャッジ日時 2023-09-08 11:53:53
合計ジャッジ時間 4,799 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
55,624 KB
testcase_01 AC 123 ms
55,708 KB
testcase_02 AC 133 ms
55,908 KB
testcase_03 AC 127 ms
55,384 KB
testcase_04 AC 127 ms
56,308 KB
testcase_05 AC 130 ms
55,460 KB
testcase_06 AC 130 ms
55,692 KB
testcase_07 AC 129 ms
55,668 KB
testcase_08 AC 132 ms
57,272 KB
testcase_09 AC 134 ms
55,628 KB
testcase_10 AC 134 ms
55,464 KB
testcase_11 AC 122 ms
55,576 KB
testcase_12 AC 131 ms
56,196 KB
testcase_13 AC 127 ms
56,012 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		long sum = 0;		
		int x = scan.nextInt();
		int N = scan.nextInt();
		int m = 1000003;
		
		for(int i=0; i<N; i++) {
			int a = scan.nextInt();
			sum += pow(x,a,m);
		}
		scan.close();
		
		System.out.println(sum % m);
	}
	
	static long pow(int x, int a, int m) {
		long ret = 1L;
		
		long v = x % m;
		while(a > 0) {
			if(a % 2 == 1) {
				ret = ret * v % m;
			}
			v = v * v % m;
			a >>>= 1;
		}
		return ret;
	}
}
0