1425A.md (1674B)
1 Source: https://codeforces.com/problemset/problem/1425/A 2 3 A. Arena of Greed 4 5 time limit per test 6 7 2 seconds 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 Lately, Mr. Chanek frequently plays the game Arena of Greed. As the name implies, the game's goal is to find the greediest of them all, who will then be crowned king of Compfestnesia. 22 23 The game is played by two people taking turns, where Mr. Chanek takes the first turn. Initially, there is a treasure chest containing $N$ gold coins. The game ends if there are no more gold coins in the chest. In each turn, the players can make one of the following moves: 24 25 * Take one gold coin from the chest. 26 * Take half of the gold coins on the chest. This move is only available if the number of coins in the chest is even. 27 28 Both players will try to maximize the number of coins they have. Mr. Chanek asks your help to find the maximum number of coins he can get at the end of the game if both he and the opponent plays optimally. 29 30 Input 31 32 The first line contains a single integer $T$ $(1 \le T \le 10^5)$ denotes the number of test cases. 33 34 The next $T$ lines each contain a single integer $N$ $(1 \le N \le 10^{18})$. 35 36 Output 37 38 $T$ lines, each line is the answer requested by Mr. Chanek. 39 40 Example 41 42 Input 43 44 ``` 45 2 46 5 47 6 48 ``` 49 50 Output 51 52 ``` 53 2 54 4 55 ``` 56 57 Note 58 59 For the first case, the game is as follows: 60 61 1. Mr. Chanek takes one coin. 62 2. The opponent takes two coins. 63 3. Mr. Chanek takes one coin. 64 4. The opponent takes one coin. 65 66 For the second case, the game is as follows: 67 68 1. Mr. Chanek takes three coins. 69 2. The opponent takes one coin. 70 3. Mr. Chanek takes one coin. 71 4. The opponent takes one coin.