結果

問題 No.16 累乗の加算
ユーザー fjafjafjafjafjafja
提出日時 2017-10-06 16:15:11
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 724 bytes
コンパイル時間 3,150 ms
コンパイル使用メモリ 74,680 KB
実行使用メモリ 58,952 KB
最終ジャッジ日時 2023-08-10 16:57:44
合計ジャッジ時間 6,691 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 118 ms
55,632 KB
testcase_01 AC 116 ms
55,548 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.Scanner;

public class N016 {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long x=sc.nextLong(),n=sc.nextLong();
		long[] a=new long[(int)n];
		for(long i=0;i<n;i++){
			a[(int)i]=sc.nextLong();
		}
		Arrays.sort(a);
		long mem=1;
		long cnt=0;
		long ans=0;
		long beki=(int)Math.pow(10, 6)+3;
		long buf=(int)Math.pow(2, 20)%beki;
		for(int i=0;i<n;i++){
			long dif=a[i]-cnt;
			if(dif>=20){
				while(dif>=20){
					dif-=20;
					mem=(mem*buf)%beki;
				}
				mem=(mem*((int)Math.pow(2, dif)%beki))%beki;

			}else{
				mem*=((int)Math.pow(x, dif)%beki);
			}
			ans=(ans+mem)%beki;
			cnt+=(a[i]-cnt);
		}
		System.out.println(ans);
	}
}
0