結果

問題 No.644 G L C C D M
ユーザー kurenai3110
提出日時 2018-02-02 23:14:42
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 604 bytes
コンパイル時間 672 ms
コンパイル使用メモリ 60,032 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-12-31 08:10:23
合計ジャッジ時間 1,625 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 17 WA * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
	if (cnt < 2)return 0;
	long long ans = 2*(cnt-1);
	for (int i = 2; 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;
			}
		}
	}
	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;
}

0