結果

問題 No.106 素数が嫌い!2
ユーザー IL_mstaIL_msta
提出日時 2015-07-03 07:42:30
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,432 bytes
コンパイル時間 2,640 ms
コンパイル使用メモリ 84,532 KB
実行使用メモリ 12,008 KB
最終ジャッジ日時 2023-09-22 05:58:27
合計ジャッジ時間 9,692 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>

#include <algorithm>
#include <cmath>

#include <string>
#include <list>
#include <queue>
#include <vector>
#include <complex>
#include <set>

/////////
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define P(p) cout<<(p)<<endl;
/////////
typedef long long LL;
typedef long double LD;
/////////
using namespace::std;
/////////
int prime[(int)1e6];
int pnum;

void makePrime(int N){
	int i,k;
	for(i=2;i <= N;++i){
		for(k=0;k<pnum; ++k){
			if(i%prime[k] == 0){
				break;
			}
		}
		if( k == pnum){
			prime[pnum] = i;
			++pnum;
		}
	}
	return;
}

int huru[1+2*(int)1e6];
void makePrime2(int N){
	for(int i=2; i<=N;++i){
		if(huru[i] == 0){
			for(int k=2;i*k<=N;++k){
				huru[i*k] = 1;
			}
			prime[pnum] = i;
			++pnum;
		}
	}

}

int inPrime(int N,int k){
	int ans = 0;
	int tempN = N;

	if(huru[N] == 0){
		return 1;
	}

	for(int i=0;i<pnum && prime[i]<=tempN ;++i){
		if(tempN%prime[i] == 0){
			++ans;
			while(tempN%prime[i] == 0){
				tempN /= prime[i];
			}
			if(ans >= k){
				return k;
			}
		}
	}
	return ans;
}

int main(void){
    std::cin.tie(0); 
    std::ios::sync_with_stdio(false);
    std::cout << std::fixed;//
    //cout << setprecision(6);//
    
	int N,K;
	cin>>N>>K;
	//makePrime(N);
	makePrime2(N);
	
	int ans=0;
	for(int i=2;i<=N;++i){
		if( inPrime(i,K) >= K){
			++ans;
		}
	}
	P(ans);
    return 0;
}
0