Loading

2021“MINIEYE杯”中国大学生算法设计超级联赛(2)1001. I love cube(思维)

Problem Description

Give you a cube with a side length of n-1. Find the number of equilateral triangles with three points on the cube point. Each side must be parallel to a certain surface of Oxy, Oxz, Oyz. Now you need to count how many such triangles there are.Each point can only be on the boundary or inner point of the cube, and the three coordinates x, y, and z of each point must be integers.

Input

The first line contains an integer T(T<=1e5) . Then T test cases follow.

Each test case contains a single Integer n(0<=n<=1e18).

If n=0, output 0

Output

For each case, print an integer, which is the answer modulo 109+7

Sample Input

2
1
2

Sample Output

0
8

观察发现三个点所有坐标都是整数的三角形只可能是第二个样例的那八种情况,即类似(0, 0, 0), (1, 0, 1), (0, 1, 1)。证明的话正三角形一条边平行于棱的情况很容易发现是不成立的,其他情况emmm

这样就只需要知道边长为n - 1的立方体包含多少边长为1,2...n-1的立方体,再将答案乘以8即可。

\(\Sigma_{i = 1}^{n-1}8\times i^3 =2(n(n-1))^2\)。n-1必须要先模一下模数!

#include <bits/stdc++.h>
#define mod 1000000007
#define int __int128
using namespace std;
inline __int128 read()
{
   int X=0,w=0; char ch=0;
   while(!isdigit(ch)) {w|=ch=='-';ch=getchar();}
   while(isdigit(ch)) X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
   return w?-X:X;
}
void print(__int128 x)
{
    if(x<0)
    {
        putchar('-');
        x=-x;
    }
    if(x>9)print(x/10);
    putchar(x%10+'0');
}
signed main() {
	signed t;
	cin >> t;
	while(t--) {
		int n;
		n = read();
		//边平行于棱的肯定没有
		if(n == 0 || n == 1) {
			cout << 0 << endl;
			continue;
		}
		n--;
		//cout << (1 + n) * n / 2 * 8 << endl;
		n %= mod;
		print((1 + n) * n % mod * (1 + n) % mod * n % mod * 2 % mod);
		cout << endl;
	}
	return 0;
}
posted @ 2021-07-23 10:42  脂环  阅读(311)  评论(0编辑  收藏  举报