結果

問題 No.826 連絡網
ユーザー CleyLCleyL
提出日時 2023-06-29 22:48:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,728 ms / 2,000 ms
コード長 764 bytes
コンパイル時間 800 ms
コンパイル使用メモリ 87,880 KB
実行使用メモリ 18,508 KB
最終ジャッジ日時 2023-09-20 17:50:43
合計ジャッジ時間 15,866 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 5 ms
4,376 KB
testcase_04 AC 6 ms
4,380 KB
testcase_05 AC 3 ms
4,380 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 AC 5 ms
4,376 KB
testcase_08 AC 4 ms
4,380 KB
testcase_09 AC 5 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 4 ms
4,376 KB
testcase_12 AC 1,122 ms
13,908 KB
testcase_13 AC 338 ms
7,272 KB
testcase_14 AC 765 ms
11,316 KB
testcase_15 AC 49 ms
4,376 KB
testcase_16 AC 456 ms
8,516 KB
testcase_17 AC 338 ms
7,176 KB
testcase_18 AC 244 ms
6,388 KB
testcase_19 AC 1,351 ms
15,732 KB
testcase_20 AC 1,324 ms
15,680 KB
testcase_21 AC 7 ms
4,376 KB
testcase_22 AC 347 ms
7,492 KB
testcase_23 AC 473 ms
8,764 KB
testcase_24 AC 165 ms
5,460 KB
testcase_25 AC 1,728 ms
18,492 KB
testcase_26 AC 202 ms
5,864 KB
testcase_27 AC 1,171 ms
14,400 KB
testcase_28 AC 835 ms
11,796 KB
testcase_29 AC 332 ms
7,456 KB
testcase_30 AC 1,716 ms
18,508 KB
testcase_31 AC 429 ms
8,260 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <set>
#include <queue>
using namespace std;

int main(){
  int n,p;cin>>n>>p;
  vector<int> A(n+1);
  set<int> X;
  queue<int> Z;
  Z.push(p);
  A[p] = 1;
  while(Z.size()){
    auto z = Z.front();Z.pop();
    for(int i = 2; z >= i*i; i++){
      if(z%i == 0){
        if(!X.count(i)){
          X.insert(i);
          for(int j = i; n >= j; j+=i){
            A[j] = 1;
            Z.push(j);
          }
        }
        while(z%i==0)z/=i;
      }
    }
    if(z != 1){
      if(!X.count(z)){
        X.insert(z);
        for(int j = z; n >= j; j+=z){
          A[j] = 1;
          Z.push(j);
        }
      }
    }
  }
  int ans = 0;
  for(int i = 0; n >= i; i++){
    ans += A[i];
  }
  cout << ans << endl;

}
0