显示原始代码
#include <bits/stdc++.h>
#define int long long
#define x first
#define y second
using namespace std;
typedef long long LL;
typedef long long ll;
typedef pair<int, int> PII;
const int N = 5e6 + 10;
const int M = 2e3 + 10;
int mod = 1e9 + 7;
map<int, int> mp, vis;
int k;
struct Link {
int x, w;
};
void bfs(int sx) {
queue<Link> que;
que.push({ sx, 0 });
while (!que.empty()) {
Link p = que.front();
que.pop();
if (vis[p.x])
continue;
vis[p.x] = 1;
mp[p.x] = p.w;
if (p.w == k)
continue;
if (p.x % 2 == 1) {
if (vis[p.x * 2] == 0)
que.push({ p.x * 2, p.w + 1 });
} else {
if (vis[p.x * 2] == 0)
que.push({ p.x * 2, p.w + 1 });
if ((p.x - 1) % 3 == 0 && vis[(p.x - 1) / 3] == 0)
que.push({ (p.x - 1) / 3, p.w + 1 });
}
}
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int n;
cin >> n >> k;
bfs(1);
int ans = 0;
for (auto it : mp) {
if (it.x <= n)
ans++;
}
cout << n - ans;
return 0;
}