結果

問題 No.106 素数が嫌い!2
ユーザー SSRSSSRS
提出日時 2020-09-03 07:31:24
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 117 ms / 5,000 ms
コード長 458 bytes
コンパイル時間 676 ms
コンパイル使用メモリ 72,752 KB
実行使用メモリ 18,920 KB
最終ジャッジ日時 2023-08-14 17:56:52
合計ジャッジ時間 2,361 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
10,960 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 47 ms
10,844 KB
testcase_05 AC 112 ms
18,840 KB
testcase_06 AC 117 ms
18,472 KB
testcase_07 AC 110 ms
18,920 KB
testcase_08 AC 6 ms
4,376 KB
testcase_09 AC 6 ms
4,380 KB
testcase_10 AC 113 ms
18,748 KB
testcase_11 AC 42 ms
10,080 KB
testcase_12 AC 111 ms
17,904 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;
int main(){
	int N, K;
	cin >> N >> K;
	vector<int> p(N + 1, -1);
	for (int i = 2; i <= N; i++){
		for (int j = i; j <= N; j += i){
			if (p[j] == -1){
				int x = j;
				while (x % i == 0){
					x /= i;
				}
				p[j] = x;
			}
		}
	}
	vector<int> f(N + 1, -1);
	f[1] = 0;
	int ans = 0;
	for (int i = 2; i <= N; i++){
		f[i] = f[p[i]] + 1;
		if (f[i] >= K){
			ans++;
		}
	}
	cout << ans << endl;
}
0