結果
問題 | No.644 G L C C D M |
ユーザー |
|
提出日時 | 2018-02-02 22:17:02 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 50 ms / 2,000 ms |
コード長 | 1,638 bytes |
コンパイル時間 | 2,058 ms |
コンパイル使用メモリ | 177,796 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-12-31 07:42:58 |
合計ジャッジ時間 | 3,070 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 27 |
ソースコード
#include <bits/stdc++.h>using namespace std;using ll = long long;bool is_prime(int n) {if (n % 2 == 0) return false;for (int i = 2; i * i <= n; i++) {if (n % i == 0) return false;}return n != 1;}vector<int> divisor(int n) {vector<int> res;for (int i = 1; i * i <= n; i++) {if (n % i == 0) {res.emplace_back(i);if (i != n / i) res.emplace_back(n / i);}}return res;}map<int, int> prime_factor(int n) {map<int, int> res;for (int i = 2; i * i <= n; i++) {while (n % i == 0) {++res[i];n /= i;}}if (n != 1) res[n] = 1;return res;}vector<int> sieve(int n) {vector<int> res;vector<bool> is_prime(n + 1, true);is_prime[0] = false;is_prime[1] = false;for (int i = 2; i <= n; i++) {if (!is_prime[i]) continue;res.emplace_back(i);for (int j = 2 * i; j <= n; j += i) is_prime[j] = false;}return res;}const ll MOD = 1000000007;int main() {cin.tie(0);ios::sync_with_stdio(false);int n, m;cin >> n >> m;ll ans = 0;for (int i = 1; i <= n / m; i++) {map<int, int> pf(prime_factor(i));ll phi = (i != 1);for (auto& p : pf) {int x = 1;for (int j = 0; j < p.second; j++) {x *= p.first;}phi *= x - x / p.first;}(ans += phi) %= MOD;}(ans *= 2) %= MOD;for (int i = 2; i <= n - 2; i++) {(ans *= i) %= MOD;}cout << ans << endl;return 0;}