-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBinary_Colouring.cpp
More file actions
43 lines (39 loc) · 983 Bytes
/
Binary_Colouring.cpp
File metadata and controls
43 lines (39 loc) · 983 Bytes
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
// we need to make an integer x from doing sigma(a[i] * 2^1)
// so make x from combination of 2's powers into -1, 0 or +1
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
ll testcases;
cin >> testcases;
for (ll testcase = 0; testcase < testcases; testcase++)
{
ll x;
cin >> x;
vector<ll> result;
ll power = 0, ans = 0;
while (ans + pow(2, power) <= x)
{
result.push_back(1);
ans += pow(2, power);
power++;
}
while(ans != x){
if(ans > x){
ans -= pow(2, power++);
result.push_back(-1);
}
else{
ans += pow(2, power++);
result.push_back(1);
}
}
ll n = result.size();
cout << n << endl;
for (ll i = 0; i < n; i++){
cout << result[i] << " ";
}
cout << endl;
}
}