luogu#P10405. 「SMOI-R1」Queue

「SMOI-R1」Queue

Background

A check-in problem……

Problem Description

There is a queue with nn people. The ii-th person in the queue has ID ii.

Starting from the first person, a number is passed to the next person one by one, until it reaches person nn. The rule for passing the number to the next person is:

  • The first person's number is 11.
  • If this person's ID is odd, then the number passed to the next person is the current number bitwise AND with the next person's ID.
  • If this person's ID is even, then the number passed to the next person is the current number bitwise XOR with the next person's ID.

Find the number passed to person nn. But computing just one case is too easy, so you need to handle tt cases.

Input Format

This problem has multiple test cases.

The first line contains an integer tt, the number of test cases.

For each test case:

There is only one number nn, representing the number of people in the queue.

Output Format

For each test case, output one number, which is the number passed to person nn.

3
1
5
10
1
5
8

Hint

Sample Explanation

For the second test case:

  • The number passed from the first person to the next is 1and2=01\operatorname{and}2=0.
  • The number passed from the second person to the next is 0xor3=30\operatorname{xor}3=3.
  • The number passed from the third person to the next is 3and4=03\operatorname{and}4=0.
  • The number passed from the fourth person to the next is 0xor5=50\operatorname{xor}5=5.

So the answer is 55.

Constraints

This problem uses bundled testdata.

subtask ID tt\leq nn\leq Score
11 10210^2 10510^5 2020
22 10610^6 10710^7
33 101810^{18} 6060

For 100%100\% of the testdata, it is guaranteed that 1t1061\le t\le10^6 and 1n10181\le n\le 10^{18}

Translated by ChatGPT 5