結果
問題 |
No.826 連絡網
|
ユーザー |
![]() |
提出日時 | 2019-05-05 09:55:09 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 576 ms / 2,000 ms |
コード長 | 2,165 bytes |
コンパイル時間 | 2,023 ms |
コンパイル使用メモリ | 173,732 KB |
実行使用メモリ | 64,560 KB |
最終ジャッジ日時 | 2024-11-24 02:39:44 |
合計ジャッジ時間 | 7,638 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 30 |
ソースコード
#include<bits/stdc++.h> #define rep(i,a,b) for(int i=a;i<b;i++) #define rrep(i,a,b) for(int i=a;i>=b;i--) #define fore(i,a) for(auto &i:a) #define all(x) (x).begin(),(x).end() //#pragma GCC optimize ("-O3") using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); } typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; } //--------------------------------------------------------------------------------------------------- vector<int> makePrimes(int n) { // [2,n] vector<int> res, pr(n + 1, 1); pr[0] = pr[1] = 0; rep(p, 2, sqrt(n) + 2) if (pr[p]) for (int x = p * 2; x <= n; x += p) pr[x] = 0; rep(p, 2, n + 1) if (pr[p]) res.push_back(p); return res; } /*--------------------------------------------------------------------------------------------------- ∧_∧ ∧_∧ (´<_` ) Welcome to My Coding Space! ( ´_ゝ`) / ⌒i / \ | | / / ̄ ̄ ̄ ̄/ | __(__ニつ/ _/ .| .|____ \/____/ (u ⊃ ---------------------------------------------------------------------------------------------------*/ int N, P; int vis[1010101]; vector<int> EP[1010101]; //--------------------------------------------------------------------------------------------------- void _main() { cin >> N >> P; auto primes = makePrimes(N); fore(p, primes) for (int x = p; x <= N; x += p) EP[x].push_back(p); int ans = 0; queue<int> que; vis[P] = 1; que.push(P); while (!que.empty()) { int cu = que.front(); que.pop(); ans++; fore(p, EP[cu]) { int to = cu / p; if (1 < to and !vis[to]) { vis[to] = 1; que.push(to); } } fore(p, primes) { int to = p * cu; if (N < to) break; if (!vis[to]) { vis[to] = 1; que.push(to); } } } cout << ans << endl; }