結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 116 ms
56,072 KB
testcase_01 AC 115 ms
55,976 KB
testcase_02 AC 119 ms
56,052 KB
testcase_03 AC 119 ms
55,492 KB
testcase_04 AC 114 ms
55,968 KB
testcase_05 AC 117 ms
56,568 KB
testcase_06 AC 115 ms
55,860 KB
testcase_07 AC 121 ms
55,780 KB
testcase_08 AC 120 ms
55,784 KB
testcase_09 AC 118 ms
55,852 KB
testcase_10 AC 120 ms
55,748 KB
testcase_11 AC 118 ms
56,140 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 135 ms
55,708 KB
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 / i;
			int b = n % i;
			if (a == 0) {
				pw.println(0);

			} else if (b == i - 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, i - 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