結果

問題 No.16 累乗の加算
ユーザー hhgfhn1hhgfhn1
提出日時 2018-10-18 22:44:17
言語 Java21
(openjdk 21)
結果
AC  
実行時間 126 ms / 5,000 ms
コード長 598 bytes
コンパイル時間 1,822 ms
コンパイル使用メモリ 74,540 KB
実行使用メモリ 41,652 KB
最終ジャッジ日時 2024-04-25 00:56:30
合計ジャッジ時間 4,222 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 115 ms
41,100 KB
testcase_01 AC 110 ms
41,652 KB
testcase_02 AC 126 ms
41,212 KB
testcase_03 AC 107 ms
40,328 KB
testcase_04 AC 120 ms
41,260 KB
testcase_05 AC 114 ms
41,264 KB
testcase_06 AC 114 ms
41,332 KB
testcase_07 AC 115 ms
41,084 KB
testcase_08 AC 119 ms
41,388 KB
testcase_09 AC 115 ms
41,340 KB
testcase_10 AC 117 ms
41,252 KB
testcase_11 AC 105 ms
40,584 KB
testcase_12 AC 116 ms
41,204 KB
testcase_13 AC 117 ms
41,000 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {

	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int x=scanner.nextInt();
		int n=scanner.nextInt();
		int mod=1000003;
		long ans=0;
		for(int i=0;i<n;i++){
			int a=scanner.nextInt();
			ans+=mod_pow(x,a,mod);
			ans=ans%mod;
		}
		System.out.println(ans);
	}

	public static long mod_pow(long x, long n, int mod) {
		if(n == 0) {
			return 1;
		}
		if(n % 2  == 0) {
			return mod_pow(x * x % mod, n / 2, mod);
		}else {
			return x * mod_pow(x, n - 1, mod) % mod;
		}
	}
	
	
}
0