結果

問題 No.106 素数が嫌い!2
ユーザー @abcde@abcde
提出日時 2019-06-16 18:20:19
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,502 bytes
コンパイル時間 1,894 ms
コンパイル使用メモリ 173,504 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-16 02:29:24
合計ジャッジ時間 10,332 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

// Efficient program to print all prime factors of a given number
// https://www.geeksforgeeks.org/print-all-prime-factors-of-a-given-number/
// 与えられた正整数についての素因数分解を計算.
// @param X: 素因数分解を行う整数.
// @return: 素因数分解 の 結果 を 返却.
map<int, int> div(int X){
    
    // 1. X を 2で割り切れなくなるまで割っていく.
    map<int, int> ret;
    while(X % 2 == 0) ret[2]++, X >>= 1;
    
    // 2. X を 3以上の奇数で, 割り切れなくなるまで順次割っていく.
    for(int i = 3; i <= sqrt(X); i += 2){
        while(X % i == 0){
            ret[i]++;
            X /= i;
        }
    }
    
    // 3. X が 2 より 大きな素数であれば, 追加.
    if(X > 2) ret[X]++;
    
    // 4. 出力.
    return ret;
}

int main() {
    
    // 1. 入力情報取得.
    int N, K;
    scanf("%d %d", &N, &K);
    
    // 2. K が 8以上ならば, ゼロを返却.
    // 2 * 3 * 5 * 7 * 11 * 13 * 17 * 19 = 9699690
    if(K >= 8){
        printf("%d\n", 0);
        return 0;
    }
    
    // 4. 2 ~ N を それぞれ素因数分解.
    int ans = 0;
    for(int i = 2; i <= N; i++){
        map<int, int> divisors = div(i);
        if(divisors.size() == K) ans++;
    }
    
    // 5. 出力.
    // ex.
    // [入力例]
    // 2000000 7
    // -> 58 で OK?.
    // 2000000 8
    // -> 0 で OK?.
    printf("%d\n", ans);
    return 0;
    
}
0