結果

問題 No.106 素数が嫌い!2
ユーザー imulanimulan
提出日時 2016-03-07 00:45:13
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,404 ms / 5,000 ms
コード長 883 bytes
コンパイル時間 1,438 ms
コンパイル使用メモリ 162,080 KB
実行使用メモリ 5,884 KB
最終ジャッジ日時 2023-10-24 20:12:10
合計ジャッジ時間 11,524 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 558 ms
5,884 KB
testcase_01 AC 22 ms
5,884 KB
testcase_02 AC 21 ms
5,884 KB
testcase_03 AC 21 ms
5,884 KB
testcase_04 AC 558 ms
5,884 KB
testcase_05 AC 1,403 ms
5,884 KB
testcase_06 AC 1,404 ms
5,884 KB
testcase_07 AC 1,404 ms
5,884 KB
testcase_08 AC 59 ms
5,884 KB
testcase_09 AC 62 ms
5,884 KB
testcase_10 AC 1,399 ms
5,884 KB
testcase_11 AC 474 ms
5,884 KB
testcase_12 AC 1,324 ms
5,884 KB
testcase_13 AC 21 ms
5,884 KB
testcase_14 AC 21 ms
5,884 KB
testcase_15 AC 22 ms
5,884 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define rep(i,n) for(i=0;i<n;++i)
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define mp make_pair
#define pb push_back
#define fi first
#define sc second

const int N=2000000;

int main()
{
	int i,j;

	//素数列挙
	bool prime[N+1];
	fill(prime,prime+N+1,true);
	prime[0]=prime[1]=false;
	for(i=2;i<=N;++i)
	{
		if(prime[i]) for(j=2;i*j<=N;++j) prime[i*j]=false;
	}

	//素数のリストの作成
	vector<int> p;
	rep(i,N+1) if(prime[i]) p.pb(i);

	//for(i=0; p[i]<=2000; ++i) printf(" %d: %d\n",i,p[i]);

	int n,k;
	cin >>n >>k;

	int ans=0;
	for(i=2; i<=n; ++i)
	{
		int t=i;
		int ct=0;
		for(j=0; p[j]*p[j]<=i; ++j)
		{
			if(t%p[j]==0)
			{
				++ct;
				while(t%p[j]==0) t/=p[j];
			}
		}

		if(prime[t]) ++ct;
		if(ct>=k) ++ans;
	}

	std::cout << ans << std::endl;
}
0