-
Notifications
You must be signed in to change notification settings - Fork 1
/
1425A.cpp
43 lines (41 loc) · 1.02 KB
/
1425A.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
#include <bits/stdc++.h>
#define FOR(i, start, end) for(int i = start; i < end; i++)
using namespace std;
typedef long long LL;
int main() {
LL t;
cin >> t;
while (t--) {
LL n;
cin >> n;
LL moves = 0, coins = 0;
while (n > 0) {
if (moves & 1) {
// NOT JONI
if (n & 1) {
n--;
} else {
if ((n % 4) == 0 && n > 8) {
n--;
} else n -= n >> 1;
}
} else {
// JONI
if (n & 1) {
coins++;
n--;
} else {
if ((n % 4) == 0 && n > 8) {
coins++;
n--;
} else {
coins += n >> 1;
n -= n >> 1;
}
}
}
moves++;
}
cout << coins << '\n';
}
}