結果

問題 No.16 累乗の加算
ユーザー mits58mits58
提出日時 2016-07-02 21:38:12
言語 Java21
(openjdk 21)
結果
AC  
実行時間 141 ms / 5,000 ms
コード長 516 bytes
コンパイル時間 3,620 ms
コンパイル使用メモリ 71,176 KB
実行使用メモリ 56,432 KB
最終ジャッジ日時 2023-09-08 12:00:05
合計ジャッジ時間 5,997 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
55,620 KB
testcase_01 AC 126 ms
55,540 KB
testcase_02 AC 137 ms
55,404 KB
testcase_03 AC 129 ms
55,564 KB
testcase_04 AC 139 ms
55,584 KB
testcase_05 AC 139 ms
55,712 KB
testcase_06 AC 137 ms
55,364 KB
testcase_07 AC 137 ms
55,828 KB
testcase_08 AC 141 ms
55,312 KB
testcase_09 AC 136 ms
56,432 KB
testcase_10 AC 135 ms
55,420 KB
testcase_11 AC 126 ms
55,420 KB
testcase_12 AC 136 ms
55,440 KB
testcase_13 AC 133 ms
55,416 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main{
	static long mod=1000003;
	static long pow(long a,long x,long m){
		if(x==0) return 1;
		else if(x%2==0) return pow((a*a)%m,x/2,m)%m;
		else return (a*pow((a*a)%m,x/2,m))%m;
	}
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		while(sc.hasNext()){
			long x=sc.nextLong();
			int n=sc.nextInt();
			long ans=0;
			for(int i=0;i<n;i++){
				long a=sc.nextLong();
				ans+=pow(x,a,mod);
				ans%=mod;
			}
			System.out.println(ans);
		}
	}
}
0