CF1810H.Last Number

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a multiset SS. Initially, S=1,2,3,…,nS = {1,2,3, \ldots, n}.

You will perform the following operation n−1n-1 times.

  • Choose the largest number SmaxS_{\text{max}} in SS and the smallest number SminS_{\text{min}} in SS. Remove the two numbers from SS, and add Smax−SminS_{\text{max}} - S_{\text{min}} into SS.

It's easy to show that there will be exactly one number left after n−1n-1 operations. Output that number.

给你一个多重集合 SS。初始时,S={1,2,3,…,n}S = \{1,2,3, \ldots, n\}。

你将执行以下操作 n−1n-1 次:

  • 选出 SS 中的最大数 SmaxS_{\text{max}} 和最小数 SminS_{\text{min}},将这两个数从 SS 中移除,并将 Smax−SminS_{\text{max}} - S_{\text{min}} 加入 SS。

容易证明,经过 n−1n-1 次操作后,SS 中恰好剩下一个数。请输出该数。

输入格式

Each test contains multiple test cases. The first line contains a single integer tt (1≤t≤1051 \le t \le 10^5) — the number of test cases. Their description follows.

For each test case, one single line contains a single integer nn (2≤n≤1092 \le n \le 10^9) — the initial size of the multiset SS.

每个测试包含多个测试用例。第一行包含一个整数 tt(1≤t≤1051 \le t \le 10^5),表示测试用例的数量。随后是这些测试用例的描述。

对于每个测试用例,一行中包含一个整数 nn(2≤n≤1092 \le n \le 10^9),表示多重集 SS 的初始大小。

输出格式

For each test case, output an integer denoting the only number left after n−1n-1 operations.

对于每个测试用例,输出一个整数,表示经过 n−1n-1 次操作后剩余的唯一数字。

输入输出样例

  • 输入#1

    5
    2
    4
    7
    15
    177567

    输出#1

    1
    2
    2
    4
    33914

说明/提示

We show how the multiset SS changes for n=4n=4.

  • Operation 11: S=1,2,3,4S={1,2,3,4}, remove 44, 11, add 33.
  • Operation 22: S=2,3,3S={2,3,3}, remove 33, 22, add 11.
  • Operation 33: S=1,3S={1,3}, remove 33, 11, add 22.
  • Final: S=2S = {2}.

Thus, the answer for n=4n = 4 is 22.

我们展示多重集 SS 在 n=4n=4 时的变化过程。

  • 操作 11:S=1,2,3,4S={1,2,3,4},移除 44 和 11,添加 33。
  • 操作 22:S=2,3,3S={2,3,3},移除 33 和 22,添加 11。
  • 操作 33:S=1,3S={1,3},移除 33 和 11,添加 22。
  • 最终:S=2S = {2}。

因此,n=4n = 4 时的答案为 22。

输入解题思路,AI测评打分。不知道怎么写?

首页