#include #define rep(i,n) for(int i=(0);i<(n);i++) using namespace std; typedef long long ll; template bool chmax(T &a, const T &b) { if (a bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; } // union-find tree with size(struct) struct UnionFind{ vector par; // 親ノード vector rank; // ランク vector size; // 連結成分のサイズ UnionFind(int n = 1) { init(n); } void init(int n = 1) { par.resize(n); rank.resize(n); size.resize(n); for (int i = 0; i < n; ++i){ par[i] = i; rank[i] = 0; size[i] = 1; } } int find(int x) { if (par[x] == x) return x; int r = find(par[x]); return par[x] = r; } bool issame(int x, int y) { return find(x) == find(y); } bool unite(int x, int y) { x = find(x); y = find(y); if (x == y) return false; if (rank[x] < rank[y]) swap(x, y); if (rank[x] == rank[y]) ++rank[x]; par[y] = x; size[x] += size[y]; return true; } int getSize(int x){ return size[find(x)]; } int getRank(int x){ return rank[find(x)]; } }; int main(){ cin.tie(0); ios::sync_with_stdio(false); int n, p; cin >> n >> p; UnionFind uf(n+1); vector isprime(n+1, true); isprime[0] = isprime[1] = false; for(int i = 2; i <= n; i++){ if(isprime[i]){ for(int j = 2 * i; j <= n; j += i){ uf.unite(i, j); isprime[j] = false; } } } cout << uf.getSize(p) << endl; }