結果

問題 No.106 素数が嫌い!2
ユーザー SSRSSSRS
提出日時 2020-09-03 07:31:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 118 ms / 5,000 ms
コード長 458 bytes
コンパイル時間 633 ms
コンパイル使用メモリ 72,904 KB
実行使用メモリ 18,816 KB
最終ジャッジ日時 2024-05-02 05:55:05
合計ジャッジ時間 2,079 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
11,136 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 48 ms
11,008 KB
testcase_05 AC 118 ms
18,788 KB
testcase_06 AC 116 ms
18,816 KB
testcase_07 AC 113 ms
18,816 KB
testcase_08 AC 6 ms
5,376 KB
testcase_09 AC 7 ms
5,376 KB
testcase_10 AC 114 ms
18,816 KB
testcase_11 AC 42 ms
10,112 KB
testcase_12 AC 116 ms
18,156 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,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