結果

問題 No.16 累乗の加算
ユーザー fjafjafjafjafjafja
提出日時 2017-10-06 16:35:49
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 762 bytes
コンパイル時間 3,382 ms
コンパイル使用メモリ 78,328 KB
実行使用メモリ 42,160 KB
最終ジャッジ日時 2024-04-28 10:23:09
合計ジャッジ時間 7,351 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 100 ms
40,300 KB
testcase_01 AC 107 ms
41,268 KB
testcase_02 AC 285 ms
41,108 KB
testcase_03 WA -
testcase_04 AC 193 ms
40,668 KB
testcase_05 AC 222 ms
41,468 KB
testcase_06 WA -
testcase_07 AC 250 ms
40,720 KB
testcase_08 WA -
testcase_09 AC 295 ms
42,160 KB
testcase_10 AC 271 ms
40,488 KB
testcase_11 AC 283 ms
40,364 KB
testcase_12 AC 284 ms
41,508 KB
testcase_13 AC 304 ms
41,812 KB
権限があれば一括ダウンロードができます

ソースコード

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=(long)Math.pow(10, 6)+3;
		long buf=(long)Math.pow(x, 9)%beki;
		long buf1=(long)Math.pow(x, 60)%beki;
		for(int i=0;i<n;i++){
			long dif=a[i]-cnt;
			if(dif>=9){
				while(dif>=9){
					dif-=9;
					mem=(mem*buf)%beki;
				}
				mem=(mem*((long)Math.pow(x, dif)%beki))%beki;
			}else{
				mem*=((long)Math.pow(x, dif)%beki);
			}
			ans=(ans+mem)%beki;
			cnt+=(a[i]-cnt);
		}
		System.out.println(ans);
	}
}
0