{"problem":{"name":"[ICPC 2018 Qingdao R] Sequence and Sequence","description":{"content":"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 $P$ is a $\\textbf{sorted}$ seque","description_type":"Markdown"},"platform":"Luogu","limit":{"time_limit":10000,"memory_limit":262144},"difficulty":{"LuoguStyle":"P7"},"is_remote":true,"is_sync":true,"sync_url":null,"sign":"LGP9885"},"statements":[{"statement_type":"Markdown","content":"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$:\n\n- Sequence $P$ is a $\\textbf{sorted}$ sequence where for all $k \\in \\mathbb{Z^+}$, $k$ appears in sequence $P$ for $(k+1)$ times ($\\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 \\}$\n- Sequence $Q$ can be derived from the following equations: \n$$\\begin{cases} Q(1) = 1 & \\\\ Q(i) = Q(i-1) + Q(P(i)) & \\text{if } i > 1 \\end{cases}$$ \nThat is to say, $Q = \\{1, 2, 4, 6, 8, 12, 16, 20, 24, 30, 36, 42, 48, 54, 62, \\dots \\}$\n\n![](https://cdn.luogu.com.cn/upload/image_hosting/ukq7qs74.png)\n\nGiven a positive integer $n$, please calculate the value of $Q(n)$.\n\n## Input\n\nThere 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:\n\nThe first and only line contains an integer $n$ ($1 \\le n \\le 10^{40}$).\n\n## Output\n\nFor each test case output one line containing one integer, indicating the value of $Q(n)$.\n\n[samples]","is_translate":false,"language":"English"}],"meta":{"iden":"LGP9885","tags":["数学","2018","O2优化","ICPC","青岛"],"sample_group":[["4\n10\n100\n1000\n987654321123456789","30\n2522\n244274\n235139898689017607381017686096176798"]],"created_at":"2026-03-03 11:09:25"}}