結果

問題 No.826 連絡網
ユーザー kk
提出日時 2020-10-08 17:58:40
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 790 bytes
コンパイル時間 4,359 ms
コンパイル使用メモリ 200,480 KB
実行使用メモリ 6,912 KB
最終ジャッジ日時 2023-09-27 11:56:08
合計ジャッジ時間 4,513 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 2 ms
4,380 KB
testcase_07 WA -
testcase_08 AC 2 ms
4,380 KB
testcase_09 WA -
testcase_10 AC 2 ms
4,380 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 6 ms
4,384 KB
testcase_16 AC 32 ms
4,384 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 79 ms
6,196 KB
testcase_21 AC 3 ms
4,376 KB
testcase_22 AC 26 ms
4,376 KB
testcase_23 AC 31 ms
4,576 KB
testcase_24 WA -
testcase_25 AC 92 ms
6,912 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 31 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for (int i=(int)(b); i<(int)(e); i++)
#define ALL(x) (x).begin(), (x).end()

const double PI = acos(-1);

int solve(int n, int p) {
  if (p == 1)
    return 1;

  vector<int> d(n+1);
  for (int i = 1; i <= n; i++) d[i] = i;
  for (int i = 2; i <= n; i++) {
    if (d[i] != i) continue;
    for (int j = 2 * i; j <= n; j += i)
      d[j] = min(d[j], i);
  }
  
  int ret = 0;
  for (int i = 2; i <= n; i++) {
    if (gcd(i, p) != 1)
      ++ret;
    else {
      if ((long long)d[i] * d[p] <= n)
        ++ret;
    }
  }

  return ret;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n, p;
  cin >> n >> p;

  cout << solve(n, p) << endl;
  
  return 0;
}
0