#16092. [ICPC 2018 Qingdao R] Sequence and Sequence

[ICPC 2018 Qingdao R] Sequence and Sequence

[ICPC 2018 Qingdao R] Sequence and Sequence

题目描述

Consider the following two sequences $P$ and $Q$. We denote $P(i)$ as the $i$-th element in sequence $P$, and $Q(i)$ as the $i$-th element in sequence $Q$:
  • Sequence PP is a sorted\textbf{sorted} sequence where for all k∈Z+k \in \mathbb{Z^+}, kk appears in sequence PP for (k+1)(k+1) times (Z+\mathbb{Z^+} is the set of all positive integers). That is to say, $P = \{1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, \dots \}$
  • Sequence QQ can be derived from the following equations:
$$\begin{cases} Q(1) = 1 & \\ Q(i) = Q(i-1) + Q(P(i)) & \text{if } i > 1 \end{cases}$$

That is to say, $Q = \{1, 2, 4, 6, 8, 12, 16, 20, 24, 30, 36, 42, 48, 54, 62, \dots \}$

Given a positive integer nn, please calculate the value of Q(n)Q(n).

输入格式

There are multiple test cases. The first line of the input contains an integer $T$ (about $10^4$), indicating the number of test cases. For each test case:

The first and only line contains an integer nn (1≤n≤10401 \le n \le 10^{40}).

输出格式

For each test case output one line containing one integer, indicating the value of $Q(n)$.
4
10
100
1000
987654321123456789
30
2522
244274
235139898689017607381017686096176798

提示

(暂无提示) 标签: P9885|数学|2018|O2优化|ICPC|青岛

来源

P9885|[ICPC 2018 Qingdao R] Sequence and Sequence