// Problem: C. p-binary
// Contest: Codeforces Round #596 (Div. 2, based on Technocup 2020 Elimination Round 2)
// URL: https://codeforces.com/contest/1247/problem/C
// Memory Limit: 512 MB
// Time Limit: 2000 ms
// Create Time : 2023-02-06 17:27:36
//
// Powered by CP Editor (https://cpeditor.org)
#include <bits/stdc++.h>
#define per(i, a, n) for (int i = n - 1;i >= a;i --)
#define rep(i, a, n) for (int i = a;i < n;i ++)
#define all(x) x.begin(), x.end()
#define SZ(x) ((int)(x).size())
#define PII pair<int, int>
#define int long long
#define PB push_back
#define se second
#define endl "\n"
#define fi first
using namespace std;
const int N = 5e5 + 50, mod = 1e9 + 7, INF = 1e18;
int t, n, m;
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n >> m;
int ok = -1;
rep (i, 1, 32) {
int x = n - m * i, cnt = 0;
if (x < 0) continue;
rep (j, 0, 32) {
if (x >> j & 1) {
cnt ++;
}
}
// 少了并 多了没办法
if (cnt <= i and x >= i) {
ok = i;
break;
}
}
cout << ok << endl;
return 0;
}
1633C - Kill the Monster | 1611A - Make Even |
1030B - Vasya and Cornfield | 1631A - Min Max Swap |
1296B - Food Buying | 133A - HQ9+ |
1650D - Twist the Permutation | 1209A - Paint the Numbers |
1234A - Equalize Prices Again | 1613A - Long Comparison |
1624B - Make AP | 660B - Seating On Bus |
405A - Gravity Flip | 499B - Lecture |
709A - Juicer | 1358C - Celex Update |
1466B - Last minute enhancements | 450B - Jzzhu and Sequences |
1582C - Grandma Capa Knits a Scarf | 492A - Vanya and Cubes |
217A - Ice Skating | 270A - Fancy Fence |
181A - Series of Crimes | 1638A - Reverse |
1654C - Alice and the Cake | 369A - Valera and Plates |
1626A - Equidistant Letters | 977D - Divide by three multiply by two |
1654B - Prefix Removals | 1654A - Maximum Cake Tastiness |