結果

問題 No.644 G L C C D M
ユーザー nebukuro09nebukuro09
提出日時 2018-02-02 22:15:54
言語 D
(dmd 2.106.1)
結果
WA  
実行時間 -
コード長 871 bytes
コンパイル時間 1,387 ms
コンパイル使用メモリ 102,952 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-09-03 18:35:44
合計ジャッジ時間 2,418 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 WA -
testcase_07 AC 1 ms
4,376 KB
testcase_08 WA -
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 WA -
testcase_12 AC 2 ms
4,380 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip;

immutable long MOD = 10^^9 + 7;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto M = s[1];
    auto X = iota(M, N+1, M).array;

    if (X.length <= 1) {
        writeln(0);
        return;
    }

    long Y = X.length.to!long;
    long ans = Y * (Y - 1) % MOD;
    auto table = new bool[](N+1);

    for (long i = M * 2; i <= N; i += M) {
        if (table[i]) continue;
        ans -= 1L * (N / i) * (N / i - 1) % MOD;
        ans %= MOD;
        for (long j = i * 2; j <= N; j += i) {
            table[j] = true;
        }
    }

    foreach (i; 1..N-1) {
        ans = ans * i % MOD;
    }
    ans = (ans + MOD) % MOD;

    ans.writeln;
}
0