結果

問題 No.1836 Max Matrix
ユーザー ks2mks2m
提出日時 2022-02-11 23:47:05
言語 Java21
(openjdk 21)
結果
AC  
実行時間 434 ms / 2,000 ms
コード長 864 bytes
コンパイル時間 2,340 ms
コンパイル使用メモリ 74,384 KB
実行使用メモリ 58,908 KB
最終ジャッジ日時 2023-09-10 06:50:03
合計ジャッジ時間 7,497 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
56,164 KB
testcase_01 AC 125 ms
55,700 KB
testcase_02 AC 346 ms
58,900 KB
testcase_03 AC 353 ms
58,908 KB
testcase_04 AC 255 ms
58,284 KB
testcase_05 AC 321 ms
58,376 KB
testcase_06 AC 275 ms
58,340 KB
testcase_07 AC 353 ms
58,344 KB
testcase_08 AC 198 ms
55,696 KB
testcase_09 AC 360 ms
58,644 KB
testcase_10 AC 284 ms
58,396 KB
testcase_11 AC 130 ms
56,148 KB
testcase_12 AC 434 ms
58,328 KB
testcase_13 AC 247 ms
58,784 KB
testcase_14 AC 270 ms
58,732 KB
testcase_15 AC 147 ms
57,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		int m = sc.nextInt();
		sc.close();

		int mod = 998244353;
		long[] ph = new long[m + 1];
		long[] pw = new long[m + 1];
		for (int i = 1; i <= m; i++) {
			ph[i] = power(i, h, mod);
			pw[i] = power(i, w, mod);
		}

		long ans = 0;
		for (int i = 1; i <= m; i++) {
			long v1 = ph[i] - ph[i - 1] + mod;
			v1 %= mod;
			long v2 = pw[i] - pw[i - 1] + mod;
			v2 %= mod;
			long v = v1 * v2 % mod;
			ans += v;
		}
		ans %= mod;
		System.out.println(ans);
	}

	static long power(long x, long n, int m) {
		if (n == 0) {
			return 1;
		}
		long val = power(x, n / 2, m);
		val = val * val % m;
		if (n % 2 == 1) {
			x %= m;
			val = val * x % m;
		}
		return val;
	}
}
0