結果

問題 No.106 素数が嫌い!2
ユーザー Mcpu3Mcpu3
提出日時 2019-03-25 13:58:05
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,799 ms / 5,000 ms
コード長 537 bytes
コンパイル時間 590 ms
コンパイル使用メモリ 72,732 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-16 21:19:57
合計ジャッジ時間 12,976 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 712 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 709 ms
5,376 KB
testcase_05 AC 1,799 ms
5,376 KB
testcase_06 AC 1,771 ms
5,376 KB
testcase_07 AC 1,779 ms
5,376 KB
testcase_08 AC 54 ms
5,376 KB
testcase_09 AC 59 ms
5,376 KB
testcase_10 AC 1,790 ms
5,376 KB
testcase_11 AC 593 ms
5,376 KB
testcase_12 AC 1,704 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

//	vector
template<typename T>
vector<T> trialDivision(T a) {
	vector<T> res;
	T i = 2;
	while (i * i <= a) {
		if (a % i == 0) {
			a /= i;
			res.push_back(i);
		}
		else ++i;
	}
	if (a != 1) res.push_back(a);
	return res;
}

int main() {
	int N, K;
	cin >> N >> K;
	int ans = 0;
	for (int i = 2; i <= N; ++i) {
		vector<int> tmp = trialDivision(i);
		tmp.erase(unique(tmp.begin(), tmp.end()), tmp.end());
		if (K <= tmp.size()) ++ans;
	}
	cout << ans;
}
0