結果

問題 No.106 素数が嫌い!2
ユーザー data9824data9824
提出日時 2015-05-31 04:16:17
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 519 ms / 5,000 ms
コード長 1,087 bytes
コンパイル時間 424 ms
コンパイル使用メモリ 65,788 KB
実行使用メモリ 7,740 KB
最終ジャッジ日時 2023-09-20 17:56:21
合計ジャッジ時間 4,836 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 226 ms
6,388 KB
testcase_01 AC 4 ms
5,332 KB
testcase_02 AC 3 ms
5,300 KB
testcase_03 AC 4 ms
5,320 KB
testcase_04 AC 225 ms
6,388 KB
testcase_05 AC 519 ms
7,740 KB
testcase_06 AC 517 ms
5,976 KB
testcase_07 AC 517 ms
6,264 KB
testcase_08 AC 25 ms
5,580 KB
testcase_09 AC 26 ms
5,512 KB
testcase_10 AC 518 ms
5,964 KB
testcase_11 AC 192 ms
6,304 KB
testcase_12 AC 492 ms
7,524 KB
testcase_13 AC 4 ms
5,304 KB
testcase_14 AC 4 ms
5,284 KB
testcase_15 AC 3 ms
5,300 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
	int n, k;
	cin >> n >> k;
	static const int MAX_N = 2000000;
	static bool isPrime[MAX_N + 1];
	fill(&isPrime[0], &isPrime[MAX_N] + 1, true);
	isPrime[0] = false;
	isPrime[1] = false;
	for (int i = 2; i <= n; ++i) {
		if (isPrime[i]) {
			for (int k = i * 2; k <= n; k += i) {
				isPrime[k] = false;
			}
		}
	}
	vector<int> primes;
	for (int i = 0; i <= n; ++i) {
		if (isPrime[i]) {
			primes.push_back(i);
		}
	}
	static bool hasManyFactors[MAX_N + 1] = { false };
	for (int x = 2; x <= n; ++x) {
		int remaining = x;
		int factorCount = 0;
		for (size_t i = 0; primes[i] * primes[i] <= remaining; ++i) {
			bool isFactor = false;
			while (remaining % primes[i] == 0) {
				remaining /= primes[i];
				isFactor = true;
			}
			if (isFactor) {
				++factorCount;
			}
		}
		if (remaining > 1) {
			++factorCount;
		}
		if (factorCount >= k) {
			hasManyFactors[x] = true;
		}
	}
	int result = count(&hasManyFactors[0], &hasManyFactors[n] + 1, true);
	cout << result << endl;
	return 0;
}
0