結果

問題 No.644 G L C C D M
ユーザー kurenai3110kurenai3110
提出日時 2018-02-02 22:52:23
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 583 bytes
コンパイル時間 671 ms
コンパイル使用メモリ 61,248 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-30 02:23:31
合計ジャッジ時間 1,968 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 WA -
testcase_07 AC 2 ms
4,376 KB
testcase_08 WA -
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 WA -
testcase_12 AC 1 ms
4,384 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 1 ms
4,384 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;

#define MOD (int)(1e9+7)

bool is_prime(int x) {
	for (int i = 2; i*i <= x; i++) {
		if (x%i == 0)return false;
	}
	return true;
}

int solve(int N,int M) {
	long long cnt = N / M;

	long long ans = cnt*(cnt - 1);
	for (int i = 2; i <= cnt; i++) {
		if(is_prime(i))ans -= (cnt / i) * (cnt / i - 1);
	}
	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