結果

問題 No.106 素数が嫌い!2
ユーザー dnishdnish
提出日時 2017-07-09 01:26:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 604 bytes
コンパイル時間 1,638 ms
コンパイル使用メモリ 162,924 KB
実行使用メモリ 10,496 KB
最終ジャッジ日時 2024-04-16 06:45:22
合計ジャッジ時間 14,175 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=(n);i<(int) N;i++)
#define p(s) cout<<(s)<<endl
using namespace std;

bool isprime[2000100];
bool ok[2000100];
void hurui(int N){
	for(int i=2;i*i<=N;i++){
		if(!isprime[i]) continue;
		for(int j=i*2;j<=N;j+=i){
			isprime[j]=false;
		}
	}
}

int main(){
	int N,K;
	cin>>N>>K;
	REP(i,2,N+1) isprime[i]=true;
	hurui(N);
	for(int i=2;i<=N;i++){
		if(ok[i]) continue;
		int cnt=0;
		REP(j,2,i+1){
			if(i%j==0&&isprime[j]){
				cnt++;
			}
		}
		if(cnt>=K) {
			for(int j=i;j<=N;j+=i){
				ok[j]=true;
			}
		}
	}
	p(count(ok,ok+N+1,true));
	return 0;
}
0