結果
問題 | No.644 G L C C D M |
ユーザー |
|
提出日時 | 2018-04-12 11:20:30 |
言語 | D (dmd 2.109.1) |
結果 |
AC
|
実行時間 | 4 ms / 2,000 ms |
コード長 | 790 bytes |
コンパイル時間 | 823 ms |
コンパイル使用メモリ | 118,316 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-13 00:23:38 |
合計ジャッジ時間 | 1,641 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 27 |
ソースコード
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; void main() { immutable long MOD = 10^^9 + 7; auto s = readln.split.map!(to!int); auto N = s[0]; auto M = s[1]; if (M > N) { writeln(0); return; } auto cnt = new int[](N+1); foreach (i; iota(M, N+1, M)) cnt[i] = 1; long ans = 1L * N/M * (N/M - 1) % MOD; for (int i = M+1; i <= N; ++i) { if (cnt[i] == 0) continue; ans -= 1L * N/i * (N/i - 1) % MOD * cnt[i] % MOD; ans = (ans + MOD) % MOD; for (int j = i + i; j <= N; j += i) cnt[j] -= cnt[i]; } foreach (i; 1..N-1) ans = ans * i % MOD; ans.writeln; }