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;
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM