結果

問題 No.16 累乗の加算
ユーザー fjafjafjafjafjafja
提出日時 2017-10-06 16:35:49
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 762 bytes
コンパイル時間 3,000 ms
コンパイル使用メモリ 74,360 KB
実行使用メモリ 56,644 KB
最終ジャッジ日時 2023-08-10 16:58:39
合計ジャッジ時間 7,409 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 118 ms
56,048 KB
testcase_01 AC 122 ms
56,128 KB
testcase_02 AC 306 ms
55,912 KB
testcase_03 WA -
testcase_04 AC 217 ms
56,148 KB
testcase_05 AC 227 ms
56,212 KB
testcase_06 WA -
testcase_07 AC 264 ms
56,124 KB
testcase_08 WA -
testcase_09 AC 312 ms
55,548 KB
testcase_10 AC 300 ms
55,808 KB
testcase_11 AC 299 ms
56,280 KB
testcase_12 AC 298 ms
56,644 KB
testcase_13 AC 301 ms
56,108 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