結果

問題 No.826 連絡網
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2019-05-05 09:55:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 650 ms / 2,000 ms
コード長 2,165 bytes
コンパイル時間 1,783 ms
コンパイル使用メモリ 173,208 KB
実行使用メモリ 64,564 KB
最終ジャッジ日時 2024-05-03 05:22:33
合計ジャッジ時間 8,467 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
27,008 KB
testcase_01 AC 21 ms
27,008 KB
testcase_02 AC 21 ms
27,008 KB
testcase_03 AC 22 ms
27,264 KB
testcase_04 AC 22 ms
27,392 KB
testcase_05 AC 22 ms
27,136 KB
testcase_06 AC 21 ms
27,136 KB
testcase_07 AC 22 ms
27,264 KB
testcase_08 AC 21 ms
27,136 KB
testcase_09 AC 22 ms
27,392 KB
testcase_10 AC 21 ms
27,264 KB
testcase_11 AC 22 ms
27,264 KB
testcase_12 AC 446 ms
54,208 KB
testcase_13 AC 146 ms
37,820 KB
testcase_14 AC 313 ms
47,372 KB
testcase_15 AC 34 ms
29,460 KB
testcase_16 AC 200 ms
40,660 KB
testcase_17 AC 158 ms
37,948 KB
testcase_18 AC 118 ms
35,368 KB
testcase_19 AC 522 ms
58,392 KB
testcase_20 AC 509 ms
57,820 KB
testcase_21 AC 22 ms
27,648 KB
testcase_22 AC 159 ms
37,948 KB
testcase_23 AC 199 ms
41,300 KB
testcase_24 AC 74 ms
33,116 KB
testcase_25 AC 650 ms
64,524 KB
testcase_26 AC 91 ms
34,464 KB
testcase_27 AC 453 ms
55,200 KB
testcase_28 AC 338 ms
48,532 KB
testcase_29 AC 142 ms
37,692 KB
testcase_30 AC 625 ms
64,564 KB
testcase_31 AC 190 ms
40,016 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}

0