CF1829G.Hits Different

普及/提高-

通过率:0%

时间限制:2.50s

内存限制:256MB

AC君温馨提醒

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

题目描述

In a carnival game, there is a huge pyramid of cans with 20232023 rows, numbered in a regular pattern as shown.

If can 929^2 is hit initially, then all cans colored red in the picture above would fall.

You throw a ball at the pyramid, and it hits a single can with number n2n^2. This causes all cans that are stacked on top of this can to fall (that is, can n2n^2 falls, then the cans directly above n2n^2 fall, then the cans directly above those cans, and so on). For example, the picture above shows the cans that would fall if can 929^2 is hit.

What is the sum of the numbers on all cans that fall? Recall that n2=n×nn^2 = n \times n.

在一场嘉年华游戏中,有一座巨大的易拉罐金字塔,共有 20232023 行,各行易拉罐按常规模式编号,如下图所示。

若最初击中编号为 929^2 的易拉罐,则上图中所有标为红色的易拉罐均会倒下。

你向该金字塔投掷一个球,击中了编号为 n2n^2 的单个易拉罐。这将导致所有堆叠在此易拉罐之上的易拉罐全部倒下(即:编号为 n2n^2 的易拉罐首先倒下,接着是直接位于 n2n^2 正上方的易拉罐倒下,再接着是位于那些易拉罐正上方的易拉罐倒下,依此类推)。例如,上图展示了击中编号为 929^2 的易拉罐时所有会倒下的易拉罐。

求所有倒下的易拉罐编号之和。注意:n2=n×nn^2 = n \times n。

输入格式

The first line contains an integer tt (1≤t≤10001 \leq t \leq 1000) — the number of test cases.

The only line of each test case contains a single integer nn (1≤n≤1061 \leq n \leq 10^6) — it means that the can you hit has label n2n^2.

第一行包含一个整数 tt(1≤t≤10001 \leq t \leq 1000)——表示测试用例的数量。

每个测试用例仅一行,包含一个整数 nn(1≤n≤1061 \leq n \leq 10^6)——表示你击中的罐头标签为 n2n^2。

输出格式

For each test case, output a single integer — the sum of the numbers on all cans that fall.

Please note, that the answer for some test cases won't fit into 32-bit integer type, so you should use at least 64-bit integer type in your programming language (like long long for C++). For all valid inputs, the answer will always fit into 64-bit integer type.

对于每个测试用例,输出一个整数——所有掉落的罐头上数字的总和。

请注意,某些测试用例的答案无法用 32 位整数类型表示,因此在编程语言中至少应使用 64 位整数类型(例如 C++ 中的 long long)。对于所有合法输入,答案均能被 64 位整数类型容纳。

输入输出样例

  • 输入#1

    10
    9
    1
    2
    3
    4
    5
    6
    10
    1434
    1000000

    输出#1

    156
    1
    5
    10
    21
    39
    46
    146
    63145186
    58116199242129511

说明/提示

The first test case is pictured in the statement. The sum of the numbers that fall is $$1^2 + 2^2 + 3^2 + 5^2 + 6^2 + 9^2 = 1 + 4 + 9 + 25 + 36 + 81 = 156.$$

In the second test case, only the can labeled 121^2 falls, so the answer is 12=11^2=1.

In the third test case, the cans labeled 121^2 and 222^2 fall, so the answer is 12+22=1+4=51^2+2^2=1+4=5.

In the fourth test case, the cans labeled 121^2 and 323^2 fall, so the answer is 12+32=1+9=101^2+3^2=1+9=10.

In the fifth test case, the cans labeled 121^2, 222^2, and 424^2 fall, so the answer is 12+22+42=1+4+16=211^2+2^2+4^2=1+4+16=21.

第一个测试用例如题面图示所示。掉落的罐头上数字的平方和为 $$1^2 + 2^2 + 3^2 + 5^2 + 6^2 + 9^2 = 1 + 4 + 9 + 25 + 36 + 81 = 156.$$

在第二个测试用例中,仅有标有 121^2 的罐头掉落,因此答案为 12=11^2=1。

在第三个测试用例中,标有 121^2 和 222^2 的罐头掉落,因此答案为 12+22=1+4=51^2+2^2=1+4=5。

在第四个测试用例中,标有 121^2 和 323^2 的罐头掉落,因此答案为 12+32=1+9=101^2+3^2=1+9=10。

在第五个测试用例中,标有 121^2、222^2 和 424^2 的罐头掉落,因此答案为 12+22+42=1+4+16=211^2+2^2+4^2=1+4+16=21。

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

首页