H. 2023秋-A-1 Sequence of Grouped Numbers

    传统题 400ms 64MiB

2023秋-A-1 Sequence of Grouped Numbers

该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。

题目描述

A sequence of grouped numbers is defined with the following pattern: the 1st group contains 1 number, which is 0×3+10\times 3+1; the 2nd group contains 2 numbers, which are 0×3+20\times 3+2 and 1×3+21\times 3+2; the 3rd group contains 3 numbers, which are 1×3+31\times 3+3, 2×3+32\times 3+3 and 3×3+33\times 3+3; and so on so forth. In general, the ii-th group contains ii numbers, which starts from the last number of the previous group plus 1, and is incremented by 3 thereafter for each number. For example, the 3rd group can be explained as the following: it contains 3 numbers, which starts from the last number of the 2nd group (that is 5) plus 1 (which gives 6), and then obtain 9 by incrementing 6 by 3, and finally get 12 by incrementing 9 by 3.

So by definition, the first 10 numbers of this sequence are: 1, 2, 5, 6, 9, 12, 13, 16, 19, and 22. They actually consists of 4 groups: {1}, {2, 5}, {6, 9, 12} and {13, 16, 19, 22}.

Your job is to tell the index of any given number in this sequence.

输入格式

Each input file contains one test case. Each case starts from a positive integer nn (105\le 10^5) in a line, which is the number of queries. Then nn lines follow, each contains a positive number that is no more than 10510^5.

输出格式

For each queried number, output in a line its index in the sequence (starting from 1). If the number is not in, output Not Found instead.

样例

4
12
16
5941
87654
6
8
2023
Not Found

限制

Java (javac) 时间限制 1000 ms 内存限制 512 MB

其他编译器 时间限制 400 ms 内存限制 64 MB

PAT2023秋季重现赛

未参加
状态
已结束
规则
IOI
题目
11
开始于
2025-8-31 14:00
结束于
2025-8-31 17:30
持续时间
3.5 小时
主持人
参赛人数
37