結果
| 問題 |
No.106 素数が嫌い!2
|
| コンテスト | |
| ユーザー |
tottoripaper
|
| 提出日時 | 2015-03-04 23:08:23 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 58 ms / 5,000 ms |
| コード長 | 848 bytes |
| コンパイル時間 | 377 ms |
| コンパイル使用メモリ | 24,064 KB |
| 実行使用メモリ | 19,204 KB |
| 最終ジャッジ日時 | 2024-06-24 06:41:15 |
| 合計ジャッジ時間 | 1,931 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 13 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:30:15: warning: format ‘%lld’ expects argument of type ‘long long int*’, but argument 2 has type ‘int*’ [-Wformat=]
30 | scanf("%lld %d", &N, &K);
| ~~~^ ~~
| | |
| | int*
| long long int*
| %d
main.cpp:30:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
30 | scanf("%lld %d", &N, &K);
| ~~~~~^~~~~~~~~~~~~~~~~~~
ソースコード
#include <cstdio>
bool isNotPrime[2000001];
int minFactor[2000001], factor_n[2000001];
int main(){
for(int i=2;i<=2000000;i+=2){
isNotPrime[i] = true;
minFactor[i] = 2;
}
minFactor[2] = 2;
for(int i=3;i<=2000000;i+=2){
if(!isNotPrime[i]){
minFactor[i] = i;
for(int j=2*i;j<=2000000;j+=i){
isNotPrime[j] = true;
minFactor[j] = i;
}
}
}
for(int i=2;i<=2000000;i++){
if(!isNotPrime[i]){
factor_n[i] = 1;
}else{
factor_n[i] = factor_n[i/minFactor[i]] + (i/minFactor[i]%minFactor[i] != 0);
}
}
int N, K;
scanf("%lld %d", &N, &K);
int res = 0;
for(int i=2;i<=N;i++){
res += factor_n[i] >= K;
}
printf("%d\n", res);
}
tottoripaper