2779. Settlers of Catan

单点时限: 5.0 sec

内存限制: 256 MB

The popular board game “Settlers of Catan” starts by creating a random board. This board consists of hexagonal resource tiles containing five different resources: clay, lumber, wool, grain, and ore. For simplicity, we will denote these by the numbers 1 to 5.

Random boards, however, often have multiple equal resource tiles next to each other. This annoys some players. Therefore, we have invented a new way of creating the playing board. Starting in the middle and spiraling outwards, each time we add a new tile to the board we choose the resource of the tile according to the following rules:

the new tile must be different from its neighboring tiles on the board so far;

in case multiple tiles are possible, we choose a resource that occurs the least number of times on the board so far;

in case multiple tiles are still possible, the new resource must have the lowest number possible.

The figure underneath shows how to spiral outwards and which resource tiles are chosen first. We are curious what the number of the resource is on the nth tile that is added to the board (starting with n = 1).

输入格式

On the first line of the input there is one integer c (1 <= c <= 200), the number of test cases. Each following test case consists of a single line with one integer n (1 <= n <= 10 000), the number of the tile we are curious about.

输出格式

For each test case, print a single line with one integer, specifying the resource of the nth tile.

样例

Input
4
1
4
10
100
Output
1
4
5
5

3 人解决,6 人已尝试。

3 份提交通过,共有 26 份提交。

8.8 EMB 奖励。

创建: 15 年前.

修改: 7 年,2 月前.

最后提交: 1 年前.

来源: NWERC 2009

题目标签