結果

問題 No.16 累乗の加算
ユーザー 37zigen37zigen
提出日時 2016-03-07 22:30:38
言語 Java21
(openjdk 21)
結果
AC  
実行時間 138 ms / 5,000 ms
コード長 605 bytes
コンパイル時間 6,682 ms
コンパイル使用メモリ 71,512 KB
実行使用メモリ 56,244 KB
最終ジャッジ日時 2023-09-08 11:56:55
合計ジャッジ時間 4,874 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
55,644 KB
testcase_01 AC 125 ms
55,372 KB
testcase_02 AC 137 ms
55,644 KB
testcase_03 AC 130 ms
55,544 KB
testcase_04 AC 132 ms
55,520 KB
testcase_05 AC 135 ms
55,264 KB
testcase_06 AC 137 ms
55,508 KB
testcase_07 AC 133 ms
56,244 KB
testcase_08 AC 136 ms
55,608 KB
testcase_09 AC 138 ms
55,640 KB
testcase_10 AC 136 ms
55,696 KB
testcase_11 AC 126 ms
55,356 KB
testcase_12 AC 135 ms
55,812 KB
testcase_13 AC 133 ms
55,308 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
	static int mod=1000003;
	public static void main(String[] args) throws Exception {
		PrintWriter pw=new PrintWriter(System.out);
		Scanner sc=new Scanner(System.in);
		long x=sc.nextLong();
		int n=sc.nextInt();
		int a;
		int ans=0;
		for(int i=0;i<n;i++){
			a=sc.nextInt();
			ans=(int)(ans+powmod(x,a))%mod;
		}
		pw.println(ans);
		pw.close();
		sc.close();
	} 
	
	
	public static long powmod(long a,int p){
		if(p==0)return 1;
		if(p%2==1){
			return a*powmod(a,p-1)%mod;
		}
		long c=powmod(a,p/2);
		return c*c%mod;
	}

}
0