結果

問題 No.1281 Cigarette Distribution
ユーザー ks2mks2m
提出日時 2020-11-06 23:00:21
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,068 bytes
コンパイル時間 1,896 ms
コンパイル使用メモリ 74,132 KB
実行使用メモリ 61,708 KB
最終ジャッジ日時 2023-09-29 19:27:22
合計ジャッジ時間 8,411 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 117 ms
54,080 KB
testcase_01 AC 115 ms
56,488 KB
testcase_02 AC 117 ms
55,784 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 119 ms
55,804 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.PrintWriter;
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 m = sc.nextInt();
		sc.close();

		int mod = 1000000007;
		PrintWriter pw = new PrintWriter(System.out);
		pw.println(n);
		if (m >= 2) {
			long n2 = n / 2;
			pw.println((n2 + 1) * (n2 - 1 + n % 2));
		}
		for (int i = 3; i <= m; i++) {
			int a = n / m;
			int b = n % m;
			if (a == 0) {
				pw.println(0);

			} else if (b == m - 1) {
				long val1 = power(a + 1, b, mod);
				long val2 = a;
				long ans = val1 * val2 % mod;
				pw.println(ans);

			} else {
				long val1 = power(a + 1, b + 1, mod);
				long val2 = power(a, m - b - 2, mod);
				long val3 = a - 1;
				long ans = val1 * val2 % mod * val3 % mod;
				pw.println(ans);
			}
		}
		pw.flush();
	}

	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) {
			val = val * x % m;
		}
		return val;
	}
}
0