結果

問題 No.826 連絡網
ユーザー finefine
提出日時 2019-05-03 21:54:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,677 bytes
コンパイル時間 1,931 ms
コンパイル使用メモリ 176,884 KB
実行使用メモリ 7,596 KB
最終ジャッジ日時 2023-08-30 06:06:55
合計ジャッジ時間 3,181 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 1 ms
4,380 KB
testcase_07 WA -
testcase_08 AC 2 ms
4,376 KB
testcase_09 WA -
testcase_10 AC 2 ms
4,380 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 8 ms
4,700 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 16 ms
6,720 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 7 ms
4,472 KB
testcase_23 AC 8 ms
4,704 KB
testcase_24 WA -
testcase_25 AC 20 ms
7,596 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 7 ms
4,696 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

bool is_prime(int n) {
    if (n % 2 == 0) return false;
    for (int i = 2; i * i <= n; i++) {
        if (n % i == 0) return false;
    }
    return n != 1;
}

vector<int> divisor(int n) {
    vector<int> res;
    for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            res.emplace_back(i);
            if (i != n / i) res.emplace_back(n / i);
        }
    }
    return res;
}

map<int, int> prime_factor(int n) {
    map<int, int> res;
    for (int i = 2; i * i <= n; i++) {
        while (n % i == 0) {
            ++res[i];
            n /= i;
        }
    }
    if (n != 1) res[n] = 1;
    return res;
}

vector<int> sieve(int n) {
    vector<int> res;
    vector<bool> is_prime(n + 1, true);
    is_prime[0] = false;
    is_prime[1] = false;
    for (int i = 2; i <= n; i++) {
        if (!is_prime[i]) continue;
        res.emplace_back(i);
        for (int j = 2 * i; j <= n; j += i) is_prime[j] = false;
    }
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, p;
    cin >> n >> p;
    if (p == 1) {
        cout << 1 << endl;
        return 0;
    }
    vector<int> s = sieve(n);
    map<int, int> pf = prime_factor(p);
    ll hoge = pf.begin()->first;
    
    vector<int> ok(n + 1, false);
    for (auto& p : pf) ok[p.first] = true;
    for (int x : s) {
        if (!ok[x] && x * hoge > n) continue;
        ok[x] = true;
        for (int i = 2 * x; i <= n; i += x) {
            ok[i] = true;
        }
    }

    int ans = 0;
    for (int i = 1; i <= n; i++) {
        ans += ok[i];
    }
    cout << ans << endl;
    return 0;
}
0