結果

問題 No.826 連絡網
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2019-05-05 09:55:09
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 609 ms / 2,000 ms
コード長 2,165 bytes
コンパイル時間 1,606 ms
コンパイル使用メモリ 172,052 KB
実行使用メモリ 64,608 KB
最終ジャッジ日時 2023-08-15 18:32:02
合計ジャッジ時間 7,302 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
27,912 KB
testcase_01 AC 11 ms
27,912 KB
testcase_02 AC 11 ms
27,896 KB
testcase_03 AC 12 ms
28,092 KB
testcase_04 AC 13 ms
28,312 KB
testcase_05 AC 12 ms
28,084 KB
testcase_06 AC 12 ms
28,056 KB
testcase_07 AC 13 ms
28,200 KB
testcase_08 AC 12 ms
28,080 KB
testcase_09 AC 12 ms
28,300 KB
testcase_10 AC 12 ms
27,936 KB
testcase_11 AC 12 ms
28,068 KB
testcase_12 AC 341 ms
54,208 KB
testcase_13 AC 88 ms
37,968 KB
testcase_14 AC 252 ms
47,404 KB
testcase_15 AC 23 ms
30,044 KB
testcase_16 AC 150 ms
41,956 KB
testcase_17 AC 88 ms
39,524 KB
testcase_18 AC 69 ms
35,304 KB
testcase_19 AC 438 ms
58,320 KB
testcase_20 AC 410 ms
57,752 KB
testcase_21 AC 13 ms
28,296 KB
testcase_22 AC 90 ms
37,860 KB
testcase_23 AC 122 ms
41,008 KB
testcase_24 AC 48 ms
33,676 KB
testcase_25 AC 609 ms
64,376 KB
testcase_26 AC 61 ms
34,540 KB
testcase_27 AC 358 ms
55,004 KB
testcase_28 AC 248 ms
49,208 KB
testcase_29 AC 99 ms
37,588 KB
testcase_30 AC 576 ms
64,608 KB
testcase_31 AC 140 ms
40,040 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