結果
| 問題 | No.644 G L C C D M | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2018-02-02 22:15:54 | 
| 言語 | D (dmd 2.109.1) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 871 bytes | 
| コンパイル時間 | 858 ms | 
| コンパイル使用メモリ | 116,488 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-06-12 23:47:07 | 
| 合計ジャッジ時間 | 1,870 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 19 WA * 8 | 
ソースコード
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;
}
            
            
            
        