-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathbleak numbers
66 lines (54 loc) · 1.18 KB
/
bleak numbers
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
Given an integer, check whether it is Bleak or not.
A number ‘n’ is called Bleak if it cannot be represented as sum of a positive number x and set bit count in x, i.e., x + countSetBits(x) is
not equal to n for any non-negative number x.
Examples :
3 is not Bleak as it can be represented
as 2 + countSetBits(2).
4 is t Bleak as it cannot be represented
as sum of a number x and countSetBits(x)
for any number x.
Input:
The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case consists of a single
line. The first line of each test case contains a single integer N to be checked for Bleak.
Output:
Print "1" or "0" (without quotes) depending on whether the number is Bleak or not.
Constraints:
1 <= T <= 1000
1 <= N <= 10000
Example:
Input:
3
4
167
3
Output:
1
0
0
*/
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
bitset<132>b;
bool call(int n)
{
int x=n - ceil(log2(n));
for (; x < n ; x++)
{
b=x;
if (x + b.count() == n)
return false;
}
return true;
}
int main() {
int t; cin>>t;
while(t--)
{
ll n; cin>>n;
if(!call(n)) cout<<0<<'\n';
else cout<<1<<'\n';
}
return 0;
}