-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patholliePS-341.cpp
48 lines (45 loc) · 942 Bytes
/
olliePS-341.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ull unsigned long long
#define flash() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const long long int MOD = 1e9 + 7;
const long long int INF = 1e18;
const long long int MAX = 1e9;
void solution()
{
ll n;
cin >> n;
vector<ll> two_pow;
two_pow.push_back(1);
for(ll i = 1 ; i <= 30 ; i++)
{
two_pow.push_back((ll)pow(2 , i));
}
ll cnt = 0;
while(n > 0)
{
ll idx = lower_bound(two_pow.begin() , two_pow.end() , n) - two_pow.begin();
ll val = *lower_bound(two_pow.begin() , two_pow.end() , n);
if(val == n)
{
cout << cnt << endl;
return;
}
cnt++;
n = n - two_pow[idx - 1];
}
cout << cnt << endl;
return;
}
int main()
{
flash();
ll t;
cin >> t;
while(t--)
{
solution();
}
return 0;
}