結果

問題 No.1343 Dividing Digit
ユーザー ks2mks2m
提出日時 2021-01-16 13:17:44
言語 Java21
(openjdk 21)
結果
AC  
実行時間 646 ms / 2,000 ms
コード長 541 bytes
コンパイル時間 4,724 ms
コンパイル使用メモリ 74,516 KB
実行使用メモリ 48,532 KB
最終ジャッジ日時 2024-05-05 15:15:34
合計ジャッジ時間 12,994 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 104 ms
40,076 KB
testcase_01 AC 105 ms
40,188 KB
testcase_02 AC 100 ms
40,060 KB
testcase_03 AC 521 ms
48,396 KB
testcase_04 AC 235 ms
46,768 KB
testcase_05 AC 329 ms
47,704 KB
testcase_06 AC 262 ms
46,112 KB
testcase_07 AC 359 ms
47,796 KB
testcase_08 AC 513 ms
48,176 KB
testcase_09 AC 504 ms
48,328 KB
testcase_10 AC 240 ms
47,304 KB
testcase_11 AC 343 ms
47,596 KB
testcase_12 AC 483 ms
48,204 KB
testcase_13 AC 438 ms
48,108 KB
testcase_14 AC 256 ms
47,144 KB
testcase_15 AC 329 ms
47,804 KB
testcase_16 AC 251 ms
46,952 KB
testcase_17 AC 570 ms
48,396 KB
testcase_18 AC 506 ms
48,532 KB
testcase_19 AC 472 ms
47,960 KB
testcase_20 AC 375 ms
48,052 KB
testcase_21 AC 483 ms
48,116 KB
testcase_22 AC 620 ms
48,340 KB
testcase_23 AC 646 ms
48,488 KB
testcase_24 AC 507 ms
48,328 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