Advertisement
deushiro

Untitled

Nov 23rd, 2019
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.48 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <map>
  4. #include <cmath>
  5. #include <bitset>
  6.  
  7. using namespace std;
  8.  
  9. int main() {
  10.     ios_base::sync_with_stdio(false);
  11.     cin.tie(0);
  12.     cout.tie(0);
  13.     int x, n, p;
  14.     bitset<32> bits;
  15.     cin >> x >> p;
  16.     int ans = -1;
  17.     for(int i = 1; i <= 32; ++i){
  18.         n = x - i * p;
  19.         bits = n;
  20.         if(i >= bits.count() && i <= n){
  21.             ans = i;
  22.             break;
  23.         }
  24.     }
  25.     cout << ans;
  26.  
  27.  
  28.  
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement