結果
| 問題 |
No.644 G L C C D M
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-10-15 21:59:10 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 5 ms / 2,000 ms |
| コード長 | 1,115 bytes |
| コンパイル時間 | 5,380 ms |
| コンパイル使用メモリ | 335,100 KB |
| 実行使用メモリ | 7,716 KB |
| 最終ジャッジ日時 | 2025-10-15 21:59:18 |
| 合計ジャッジ時間 | 6,853 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 27 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using mint = modint1000000007;
// linear sieve
vector<bool> isp;
vector<int> ps, pf, mu;
void sieve(int mx) {
isp.resize(mx+1);
pf.resize(mx+1);
mu.resize(mx+1);
mu[1] = 1;
rep(i, mx+1) pf[i] = i;
for (int i = 2; i <= mx; ++i) {
if (pf[i] == i) isp[i] = true, ps.push_back(i), mu[i] = -1;
rep(j, ps.size()) {
int x = ps[j]*i;
if (x > mx) break;
pf[x] = ps[j];
if (i%ps[j] == 0) {
mu[i*ps[j]] = 0;
break;
}
mu[i*ps[j]] = -mu[i];
}
}
}
int main() {
int n, m;
cin >> n >> m;
if (n < m) {
puts("0");
return 0;
}
int k = n/m;
sieve(k);
mint ans;
for (int p = 1; p <= k; ++p) {
ans += mint(mu[p])*(k/p)*(k/p);
}
ans -= 1;
for (int i = 1; i <= n-2; ++i) {
ans *= i;
}
cout << ans.val() << '\n';
return 0;
}