結果

問題 No.1281 Cigarette Distribution
ユーザー tenten
提出日時 2020-11-09 12:22:29
言語 Java
(openjdk 23)
結果
AC  
実行時間 273 ms / 2,000 ms
コード長 966 bytes
コンパイル時間 2,628 ms
コンパイル使用メモリ 74,460 KB
実行使用メモリ 47,000 KB
最終ジャッジ日時 2024-07-22 16:00:42
合計ジャッジ時間 7,989 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    static final int MOD = 1000000007;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        StringBuilder sb = new StringBuilder();
        for (int i = 1; i <= m; i++) {
            int q = (n + 1) / i;
            int r = (n + 1) % i;
            int plus = r;
            int even = i - r - 1;
            long ans = 1;
            ans *= pow(q + 1, plus);
            ans %= MOD;
            ans *= pow(q, even);
            ans %= MOD;
            ans *= q - 1;
            ans %= MOD;
            sb.append(ans).append("\n");
        }
        System.out.print(sb);
    }
    
    static long pow(long x, long p) {
        if (p == 0) {
            return 1;
        } else if (p % 2 == 0) {
            return pow(x * x % MOD, p / 2);
        } else {
            return x * pow(x, p - 1) % MOD;
        }
    }
}
0