結果

問題 No.16 累乗の加算
ユーザー kano_town
提出日時 2014-11-19 17:47:53
言語 Java
(openjdk 23)
結果
AC  
実行時間 146 ms / 5,000 ms
コード長 530 bytes
コンパイル時間 3,515 ms
コンパイル使用メモリ 74,404 KB
実行使用メモリ 41,384 KB
最終ジャッジ日時 2024-06-26 04:47:46
合計ジャッジ時間 6,929 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Yukicoder16 {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int N = sc.nextInt();
		long res = 0;
		for (int i = 0; i < N; i++) {
			res += powMod(x, sc.nextInt()) % 1000003;
		}
		System.out.println(res % 1000003);
	}

	private static long powMod(long a, int n) {
		long res = 1;
		for (; n > 0; n>>=1) {
			res = (n & 1) == 1 ? (a * res) % 1000003 : res;
			a = (a * a) % 1000003;
		}
		return res;
	}
}
0