結果
問題 | No.826 連絡網 |
ユーザー |
|
提出日時 | 2020-10-08 18:40:56 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 97 ms / 2,000 ms |
コード長 | 995 bytes |
コンパイル時間 | 1,818 ms |
コンパイル使用メモリ | 196,688 KB |
最終ジャッジ日時 | 2025-01-15 03:30:58 |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 30 |
ソースコード
#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; }