結果
問題 |
No.644 G L C C D M
|
ユーザー |
![]() |
提出日時 | 2018-02-02 23:21:43 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 625 bytes |
コンパイル時間 | 451 ms |
コンパイル使用メモリ | 60,616 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-12-31 08:14:11 |
合計ジャッジ時間 | 1,403 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 19 WA * 8 |
ソースコード
#include <iostream> #include <vector> #include <algorithm> #include <string> using namespace std; #define MOD (int)(1e9+7) int solve(int N,int M) { long long cnt = N / M; long long ans = 0; for (int i = 1; i <= cnt; i++) { ans += 2 * (cnt - i); int x = i; for (int j = 2; j*j <= x; j++) { if (x%j == 0) { ans -= 2 * ((cnt - i) / j); while (x%j == 0)x /= j; } } if (x != 1) { ans -= 2 * ((cnt - i) / x); } } ans %= MOD; for (int i = N - 2; i >= 1; i--) { ans *= i; ans %= MOD; } return ans; } int main() { int N, M; cin >> N >> M; cout << solve(N, M) << endl; return 0; }