結果

問題 No.1343 Dividing Digit
ユーザー ks2mks2m
提出日時 2021-01-16 13:17:44
言語 Java19
(openjdk 21)
結果
AC  
実行時間 526 ms / 2,000 ms
コード長 541 bytes
コンパイル時間 3,859 ms
コンパイル使用メモリ 72,192 KB
実行使用メモリ 62,112 KB
最終ジャッジ日時 2023-08-18 09:42:27
合計ジャッジ時間 13,262 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
56,044 KB
testcase_01 AC 124 ms
55,936 KB
testcase_02 AC 124 ms
55,688 KB
testcase_03 AC 502 ms
60,160 KB
testcase_04 AC 244 ms
59,752 KB
testcase_05 AC 320 ms
60,556 KB
testcase_06 AC 275 ms
60,284 KB
testcase_07 AC 364 ms
60,328 KB
testcase_08 AC 482 ms
60,720 KB
testcase_09 AC 516 ms
60,428 KB
testcase_10 AC 266 ms
60,080 KB
testcase_11 AC 349 ms
60,404 KB
testcase_12 AC 438 ms
60,784 KB
testcase_13 AC 453 ms
60,788 KB
testcase_14 AC 263 ms
59,784 KB
testcase_15 AC 333 ms
60,504 KB
testcase_16 AC 262 ms
59,896 KB
testcase_17 AC 473 ms
60,288 KB
testcase_18 AC 524 ms
60,440 KB
testcase_19 AC 462 ms
60,328 KB
testcase_20 AC 382 ms
60,108 KB
testcase_21 AC 504 ms
62,112 KB
testcase_22 AC 473 ms
60,616 KB
testcase_23 AC 526 ms
60,364 KB
testcase_24 AC 451 ms
60,392 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		sc.close();

		long m = 0;
		for (int i = 0; i < n; i++) {
			m += a[i];
		}

		long ans = 0;
		long ki = 1;
		for (int i = 0; i < n; i++) {
			long c = a[n - 1 - i] * ki % m;
			ans += c;
			ans %= m;
			ki *= k;
			ki %= m;
		}
		System.out.println(ans);
	}
}
0