結果

問題 No.16 累乗の加算
ユーザー Mcpu3Mcpu3
提出日時 2018-09-01 11:43:45
言語 Java21
(openjdk 21)
結果
AC  
実行時間 127 ms / 5,000 ms
コード長 436 bytes
コンパイル時間 1,821 ms
コンパイル使用メモリ 71,556 KB
実行使用メモリ 56,424 KB
最終ジャッジ日時 2023-10-13 13:55:49
合計ジャッジ時間 4,511 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 115 ms
56,272 KB
testcase_01 AC 119 ms
56,184 KB
testcase_02 AC 124 ms
56,144 KB
testcase_03 AC 118 ms
55,980 KB
testcase_04 AC 124 ms
56,424 KB
testcase_05 AC 126 ms
56,240 KB
testcase_06 AC 124 ms
55,728 KB
testcase_07 AC 125 ms
55,768 KB
testcase_08 AC 127 ms
55,888 KB
testcase_09 AC 123 ms
56,232 KB
testcase_10 AC 121 ms
56,120 KB
testcase_11 AC 115 ms
55,708 KB
testcase_12 AC 124 ms
55,616 KB
testcase_13 AC 120 ms
56,072 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

class Main{
	public static long p(long x,long n) {
		long r;
		if(1>n) return 1;
		r=p(x*x%1000003,n/2);
		if(n%2!=0) r=r*x%1000003;
		return r;
	}
	
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		long x=sc.nextLong(),n=sc.nextLong(),a,s=0,i;
		for(i=0;i<n;i++) {
			a=sc.nextLong();
			s=(s+p(x,a))%1000003;
		}
		sc.close();
		System.out.print(s);
	}
}
0