結果

問題 No.1281 Cigarette Distribution
ユーザー ks2mks2m
提出日時 2020-11-06 23:22:51
言語 Java21
(openjdk 21)
結果
AC  
実行時間 512 ms / 2,000 ms
コード長 1,074 bytes
コンパイル時間 3,463 ms
コンパイル使用メモリ 74,272 KB
実行使用メモリ 60,028 KB
最終ジャッジ日時 2023-09-29 19:39:00
合計ジャッジ時間 9,630 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 116 ms
55,852 KB
testcase_01 AC 113 ms
55,920 KB
testcase_02 AC 109 ms
55,600 KB
testcase_03 AC 113 ms
56,140 KB
testcase_04 AC 115 ms
55,496 KB
testcase_05 AC 114 ms
55,852 KB
testcase_06 AC 115 ms
55,888 KB
testcase_07 AC 114 ms
55,508 KB
testcase_08 AC 116 ms
56,068 KB
testcase_09 AC 114 ms
56,120 KB
testcase_10 AC 115 ms
55,772 KB
testcase_11 AC 115 ms
56,312 KB
testcase_12 AC 264 ms
59,068 KB
testcase_13 AC 434 ms
59,932 KB
testcase_14 AC 364 ms
59,260 KB
testcase_15 AC 285 ms
59,240 KB
testcase_16 AC 343 ms
59,692 KB
testcase_17 AC 141 ms
55,788 KB
testcase_18 AC 494 ms
59,168 KB
testcase_19 AC 512 ms
59,024 KB
testcase_20 AC 505 ms
59,468 KB
testcase_21 AC 389 ms
59,244 KB
testcase_22 AC 429 ms
60,028 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);
		if (m >= 2) {
			long n2 = n / 2;
			pw.println((n2 + 1) * (n2 - 1 + n % 2) % mod);
		}
		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