結果

問題 No.106 素数が嫌い!2
ユーザー furafura
提出日時 2020-04-15 23:23:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,056 bytes
コンパイル時間 2,112 ms
コンパイル使用メモリ 204,456 KB
実行使用メモリ 8,000 KB
最終ジャッジ日時 2024-04-09 19:04:41
合計ジャッジ時間 4,870 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 135 ms
7,856 KB
testcase_01 AC 8 ms
7,816 KB
testcase_02 AC 8 ms
7,744 KB
testcase_03 AC 9 ms
7,856 KB
testcase_04 AC 138 ms
7,856 KB
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 AC 25 ms
7,804 KB
testcase_09 AC 25 ms
7,744 KB
testcase_10 RE -
testcase_11 AC 119 ms
7,900 KB
testcase_12 RE -
testcase_13 AC 9 ms
7,860 KB
testcase_14 AC 9 ms
7,832 KB
testcase_15 AC 10 ms
7,908 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

class linear_sieve{
	vector<int> lpf,p;
public:
	linear_sieve(int n):lpf(n+1){
		for(int i=2;i<=n;i++){
			if(lpf[i]==0){
				lpf[i]=i;
				p.emplace_back(i);
			}
			for(int j=0;j<p.size()&&p[j]<=lpf[i]&&i*p[j]<=n;j++) lpf[i*p[j]]=p[j];
		}
	}

	const vector<int>& primes()const{ return p; }

	bool is_prime(int a)const{
		assert(a<=(int)lpf.size()-1);
		return a>0 && lpf[a]==a;
	}

	map<int,int> prime_factorize(int a)const{
		assert(a<=(int)lpf.size()-1);
		map<int,int> pf;
		for(;a>1;a/=lpf[a]) ++pf[lpf[a]];
		return pf;
	}

	int number_of_divisors(int a)const{
		assert(a<=(int)lpf.size()-1);
		int res=1,cnt=0,pre=-1;
		for(;a>1;a/=lpf[a]){
			if(pre==-1 || pre==lpf[a]){
				cnt++;
			}
			else{
				res*=cnt+1;
				cnt=1;
			}
			pre=lpf[a];
		}
		return res*(cnt+1);
	}
};

int main(){
	int n,k; scanf("%d%d",&n,&k);

	linear_sieve LS(1e6);

	int ans=0;
	for(int i=2;i<=n;i++) if(LS.prime_factorize(i).size()>=k) ans++;
	printf("%d\n",ans);

	return 0;
}
0