結果

問題 No.644 G L C C D M
ユーザー nebukuro09nebukuro09
提出日時 2018-02-02 22:25:30
言語 D
(dmd 2.109.1)
結果
WA  
実行時間 -
コード長 818 bytes
コンパイル時間 887 ms
コンパイル使用メモリ 116,644 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-12 23:47:13
合計ジャッジ時間 1,500 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19 WA * 8
権限があれば一括ダウンロードができます

ソースコード

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!long);
    auto N = s[0];
    auto M = s[1];
    auto X = N / M;

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

    long ans = X * (X - 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