Codeforces Round #642 (Div. 3) C. Board Moves

You are given a board of size n×nn×n , where nn is odd (not divisible by 22 ). Initially, each cell of the board contains one figure.

In one move, you can select exactly one figure presented in some cell and move it to one of the cells sharing a side or a corner with the current cell, i.e. from the cell (i,j)(i,j) you can move the figure to cells:

  • (i1,j1)(i−1,j−1) ;
  • (i1,j)(i−1,j) ;
  • (i1,j+1)(i−1,j+1) ;
  • (i,j1)(i,j−1) ;
  • (i,j+1)(i,j+1) ;
  • (i+1,j1)(i+1,j−1) ;
  • (i+1,j)(i+1,j) ;
  • (i+1,j+1)(i+1,j+1) ;

Of course, you can not move figures to cells out of the board. It is allowed that after a move there will be several figures in one cell.

Your task is to find the minimum number of moves needed to get all the figures into one cell (i.e. n21n2−1 cells should contain 00 figures and one cell should contain n2n2 figures).

You have to answer tt independent test cases.

Input

The first line of the input contains one integer tt (1t2001≤t≤200 ) — the number of test cases. Then tt test cases follow.

The only line of the test case contains one integer nn (1n<51051≤n<5⋅105 ) — the size of the board. It is guaranteed that nn is odd (not divisible by 22 ).

It is guaranteed that the sum of nn over all test cases does not exceed 51055⋅105 (n5105∑n≤5⋅105 ).

Output

For each test case print the answer — the minimum number of moves needed to get all the figures into one cell.

Example
Input
Copy
3
1
5
499993
Output
Copy
0
40
41664916690999888

找规律。可以看到正方形的每一个“圈”到中心的最小距离都是一样的(数一下就能发现规律)。然后把整个正方形分成八个小三角形+八条线或者直接按照圈来统计都行。
复制代码
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        long long n,ans=0;
        long long i;
        cin>>n;
        for(i=2;i<=n/2+1;i++)
        {
            ans+=(i-2)*(i-1);
        } 
        ans*=8;
        for(i=1;i<=n/2+1;i++)
        {
            ans+=(i-1)*8;
        }      
        cout<<ans<<endl;                                                                              
    }
    return 0;
}
复制代码

 

posted @   脂环  阅读(267)  评论(0编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
点击右上角即可分享
微信分享提示
主题色彩