結果

問題 No.16 累乗の加算
ユーザー spaciaspacia
提出日時 2016-01-04 11:21:27
言語 Java21
(openjdk 21)
結果
AC  
実行時間 44 ms / 5,000 ms
コード長 878 bytes
コンパイル時間 2,855 ms
コンパイル使用メモリ 73,528 KB
実行使用メモリ 49,584 KB
最終ジャッジ日時 2023-09-08 11:52:11
合計ジャッジ時間 4,096 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
49,244 KB
testcase_01 AC 41 ms
49,136 KB
testcase_02 AC 43 ms
49,188 KB
testcase_03 AC 42 ms
49,068 KB
testcase_04 AC 42 ms
47,084 KB
testcase_05 AC 42 ms
49,248 KB
testcase_06 AC 43 ms
49,408 KB
testcase_07 AC 42 ms
49,200 KB
testcase_08 AC 43 ms
49,584 KB
testcase_09 AC 44 ms
49,260 KB
testcase_10 AC 43 ms
49,248 KB
testcase_11 AC 42 ms
49,236 KB
testcase_12 AC 44 ms
47,764 KB
testcase_13 AC 43 ms
49,132 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.math.*;

class Main {
	
	public static void out (Object o) {
		System.out.println(o);
	}
	
	public static int power (int x , int a , int m) {
		long x2 = x;
		long ret = 1;
		while (a > 0) {
			if (a % 2 == 1)
				ret = ret * x2 % m;
			//out("ret = " + ret + " , a = " + a + " , x2 = " + x2);
			a /= 2;
			x2 = x2 * x2 % m;
		}
		return (int)ret;
	}
	
	public static void main (String[] args) throws IOException {
		BufferedReader br = 
			new BufferedReader(new InputStreamReader(System.in));
		
		String[] line1 = br.readLine().split(" ");
		String[] line2 = br.readLine().split(" ");
		
		int x = Integer.parseInt(line1[0]);
		int n = Integer.parseInt(line1[1]);
		int ans = 0, m = 1000003;
		
		for (int i = 0; i < n; i++) {
			int a = Integer.parseInt(line2[i]);
			ans = (ans + power(x,a,m)) % m;
		}
		
		out(ans);
	}
}
0