結果

問題 No.826 連絡網
ユーザー ooaiu
提出日時 2025-09-02 23:22:28
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 33 ms / 2,000 ms
コード長 1,034 bytes
コンパイル時間 3,318 ms
コンパイル使用メモリ 282,080 KB
実行使用メモリ 15,168 KB
最終ジャッジ日時 2025-09-02 23:22:33
合計ジャッジ時間 4,790 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main() {
    int n, p;
    cin >> n >> p;
    vector<int> ps;
    vector<int> vis(n + 1), lpf(n + 1, -1), fs(n + 1);
    for (int64_t x = 2; x * x <= p; x++) {
        if (p % x == 0) {
            while (p % x == 0) {
                ps.push_back(x);
                p /= x;
            }
        }
    }
    if (p != 1) ps.push_back(p);
    ps.erase(unique(ps.begin(), ps.end()), ps.end());
    for (int x : ps) vis[x] = 1;

    for (int p = 2; p <= n; p++) {
        if (lpf[p] != -1) continue;
        for (int q = p; q <= n; q += p) {
            if (lpf[q] == -1) lpf[q] = p;
        }
    }
    for (int i = 0; i < (int)ps.size(); i++) {
        int p = ps[i];
        for (int q = p; q <= n; q += p) {
            int s = q / p;
            fs[q] = 1;
            if (lpf[s] == s && !vis[s]) {
                vis[s] = 1;
                ps.push_back(s);
            }
        }
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) ans += fs[i];
    cout << ans << "\n";
}
0