結果

問題 No.826 連絡網
ユーザー kk
提出日時 2020-10-08 18:40:56
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 88 ms / 2,000 ms
コード長 995 bytes
コンパイル時間 2,004 ms
コンパイル使用メモリ 201,488 KB
実行使用メモリ 10,732 KB
最終ジャッジ日時 2023-09-27 11:56:56
合計ジャッジ時間 3,580 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 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 65 ms
8,664 KB
testcase_13 AC 26 ms
5,400 KB
testcase_14 AC 46 ms
6,088 KB
testcase_15 AC 6 ms
4,376 KB
testcase_16 AC 29 ms
5,840 KB
testcase_17 AC 26 ms
5,364 KB
testcase_18 AC 20 ms
4,780 KB
testcase_19 AC 75 ms
9,744 KB
testcase_20 AC 73 ms
9,416 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 24 ms
5,308 KB
testcase_23 AC 29 ms
5,876 KB
testcase_24 AC 14 ms
4,380 KB
testcase_25 AC 85 ms
10,732 KB
testcase_26 AC 16 ms
4,584 KB
testcase_27 AC 67 ms
9,052 KB
testcase_28 AC 48 ms
7,356 KB
testcase_29 AC 25 ms
5,224 KB
testcase_30 AC 88 ms
10,704 KB
testcase_31 AC 29 ms
5,760 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);

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<long long> 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<long long>(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