#P9885. [ICPC2018 Qingdao R] Sequence and Sequence

    ID: 9267 Type: RemoteJudge 10000ms 256MiB Tried: 0 Accepted: 0 Difficulty: 7 Uploaded By: Tags>数学2018O2优化ICPC青岛

[ICPC2018 Qingdao R] Sequence and Sequence

题目描述

Consider the following two sequences PP and QQ. We denote P(i)P(i) as the ii-th element in sequence PP, and Q(i)Q(i) as the ii-th element in sequence QQ:

  • Sequence PP is a sorted\textbf{sorted} sequence where for all kZ+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 TT (about 10410^4), indicating the number of test cases. For each test case:

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

输出格式

For each test case output one line containing one integer, indicating the value of Q(n)Q(n).

题目大意

题目描述

考虑下列两个序列 PPQQ。我们用 P(i)P(i) 表示序列 PP 中的第 ii 个元素,用 Q(i)Q(i) 表示序列 QQ 中的第 ii 个元素:

  • 序列 PP 是一个已排序的序列,其中,对于所有 kZ+k \in \mathbb{Z^+}kk 在序列 PP 中出现 (k+1)(k+1) 次(Z+\mathbb{Z^+} 为正整数集)。也就是说,$P = \{1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, \dots \}$
  • 序列 QQ 可以由以下方程导出:
$$\begin{cases} Q(1) = 1 & \\ Q(i) = Q(i-1) + Q(P(i)) & \text{if } i > 1 \end{cases} $$

也就是说,$Q = \{1, 2, 4, 6, 8, 12, 16, 20, 24, 30, 36, 42, 48, 54, 62, \dots \}$。

给定一个正整数 nn,请计算 Q(n)Q(n) 的值。

输入格式

本题的测试点包含多组测试数据。

第一行输入包含一个整数 TT10410^4 左右),表示测试数据的数量。对于每组测试数据:

  • 第一行(也是唯一一行)包含一个整数 nn1n10401 \le n \le 10^{40})。

输出格式

对于每组测试数据,输出一行,包含一个整数,表示 Q(n)Q(n) 的值。

4
10
100
1000
987654321123456789
30
2522
244274
235139898689017607381017686096176798