結果

問題 No.16 累乗の加算
ユーザー fjafjafjafjafjafja
提出日時 2017-10-06 16:14:16
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 804 bytes
コンパイル時間 3,213 ms
コンパイル使用メモリ 78,796 KB
実行使用メモリ 59,560 KB
最終ジャッジ日時 2023-08-10 16:57:36
合計ジャッジ時間 7,461 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
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);
			}
			System.out.println("x="+x+"dif="+dif+"mem="+mem);
			ans=(ans+mem)%beki;
			cnt+=(a[i]-cnt);
			System.out.println(ans);
		}
		System.out.println(ans);
	}
}
0