結果

問題 No.826 連絡網
ユーザー kk
提出日時 2020-10-08 18:39:21
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 978 bytes
コンパイル時間 1,676 ms
コンパイル使用メモリ 200,132 KB
実行使用メモリ 7,192 KB
最終ジャッジ日時 2023-09-27 11:56:52
合計ジャッジ時間 3,739 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

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);

long long gcd(long long a, long long b) {
  if (b == 0)
    return a;
  return gcd(b, a%b);    
}

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 = 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 {
      bool ck = false;
      ck |= 2 * d[p] <= n && 2 * d[i] <= n;
      ck |= p * d[i] <= n;
      ck |= i * d[p] <= n;
      if (ck)
        ++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