結果

問題 No.1281 Cigarette Distribution
ユーザー ks2mks2m
提出日時 2020-11-06 23:15:48
言語 Java21
(openjdk 21)
結果
AC  
実行時間 538 ms / 2,000 ms
コード長 984 bytes
コンパイル時間 3,781 ms
コンパイル使用メモリ 73,908 KB
実行使用メモリ 61,408 KB
最終ジャッジ日時 2023-09-29 19:33:45
合計ジャッジ時間 10,658 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
55,432 KB
testcase_01 AC 124 ms
55,740 KB
testcase_02 AC 122 ms
56,172 KB
testcase_03 AC 123 ms
55,420 KB
testcase_04 AC 125 ms
55,740 KB
testcase_05 AC 121 ms
55,948 KB
testcase_06 AC 124 ms
55,460 KB
testcase_07 AC 125 ms
55,772 KB
testcase_08 AC 127 ms
56,080 KB
testcase_09 AC 124 ms
55,688 KB
testcase_10 AC 124 ms
55,732 KB
testcase_11 AC 125 ms
55,740 KB
testcase_12 AC 278 ms
58,736 KB
testcase_13 AC 455 ms
59,152 KB
testcase_14 AC 388 ms
59,088 KB
testcase_15 AC 312 ms
58,928 KB
testcase_16 AC 357 ms
59,544 KB
testcase_17 AC 138 ms
56,428 KB
testcase_18 AC 534 ms
61,408 KB
testcase_19 AC 538 ms
59,348 KB
testcase_20 AC 534 ms
59,264 KB
testcase_21 AC 415 ms
59,208 KB
testcase_22 AC 448 ms
59,324 KB
権限があれば一括ダウンロードができます

ソースコード

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);
		for (int i = 2; 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