-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathA.cpp
More file actions
55 lines (50 loc) · 880 Bytes
/
Copy pathA.cpp
File metadata and controls
55 lines (50 loc) · 880 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
44
45
46
47
48
49
50
51
52
53
54
55
#define fast ios::sync_with_stdio(false); cin.tie(0)
#define foru(i, k, n) for (int i = k; i < n; i++)
#define ford(i, k, n) for (int i = k; i >= n; i--)
#define pb push_back
#define mp make_pair
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <list>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int sz = 2e3;
ll dp[sz];
ll solve(ll n) {
ll tot = 0;
bool me = 1;
while (n) {
if (n & 1) {
n--;
if (me)tot++;
}
else {
if (n % 4 == 0 && n != 4) {
n--;
if (me)tot++;
}
else {
if (me)tot += (n >> 1);
n >>= 1;
}
}
me = !me;
}
return tot;
}
int main() {
fast;
int t;
cin >> t;
while (t--) {
ll n;
cin >> n;
cout << solve(n) << endl;
}
return 0;
}