#P8873. [传智杯 #5 初赛] E-梅莉的市场经济学

[传智杯 #5 初赛] E-梅莉的市场经济学

Background

Mellie took an economics elective this semester. However, since her major is psychology, she is really not good at analyzing economics. Because of this, she often complains that she cannot learn it and wants to drop the course.

But if she drops it now, she will not have enough credits this semester. So, based on what she “experienced in a dream,” she “made up” a market model that is simple to the point of being unrealistic, and wrote an essay using this model. To make it easier to create charts, she needs to write a program to query the market trade balance at each moment.

Problem Description

The daily trade balance in the market can be seen as a periodic sequence aa: $\color{red}[0],\color{blue}[0,\allowbreak 1,\allowbreak 0,\allowbreak -1,\allowbreak 0],\color{red}[0,\allowbreak 1,\allowbreak 2,\allowbreak 1,\allowbreak 0,\allowbreak -1,\allowbreak -2,\allowbreak -1,\allowbreak 0],\allowbreak \color{blue}[0,\allowbreak 1,\allowbreak 2,\allowbreak 3,\allowbreak 2,\allowbreak 1,\allowbreak 0,\allowbreak -1,\allowbreak -2,\allowbreak -3,\allowbreak -2,\allowbreak -1,\allowbreak 0]\dots$.

More specifically, aa can be divided into infinitely many segments. The content of the ii-th segment is $\{0,\allowbreak 1,\allowbreak \cdots,\allowbreak i,\allowbreak i-1,\allowbreak \cdots,0,\allowbreak -1,\allowbreak \cdots,\allowbreak -i,\allowbreak -i+1,\allowbreak \cdots 0\}$. The figure below shows the plot of some of the first points in sequence aa on the coordinate axes:

Now Mellie makes qq queries to the market. Each time, she is given an integer kk and wants to find the value of aka_k.

Input Format

  • The first line contains a positive integer qq, which represents the number of queries.
  • The next qq lines each contain a positive integer kk, describing each query.

Output Format

  • Output a total of qq lines. For each query, output the corresponding result.
9
1
10
100
1000
10000
100000
1000000
10000000
100000000
0
1
6
-9
-11
-128
406
1629
5154

Hint

Constraints: for all testdata, 1q1051 \leq q \leq 10^5, 1k4×10181 \leq k \leq 4\times 10^{18}.

Translated by ChatGPT 5