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
题意:
求边长为n-1的正方体能画出多少个等边三角形
思路:
等边三角形画法如下
边长为1的三角形可以画出8个等边三角形
边长为n的正方体可以分为边长为1的正方体,边长为2的正方体…边长为n的正方体,一个正方体可以画出8个等边三角形
所以我们需要计算一共可以分为多少个正方体?
边长为n的正方体可以分为n * n * n个边长为1的正方体
边长为n的正方体可以分为(n-1)*(n-1) *(n-1)个边长为2的正方体,以此类推
边长为n的正方形一共可以分为∑(i=0)~(i=n-1)((n-i) ^3) ,由公式得最终结果为(n*(n+1)/2) ^ 2
注意题目给的正方体边长是n-1
代码:
#include<bits/stdc++.h>
using namespace std;
int mod=1000000007;
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
long long n;
scanf("%lld",&n);
if(n==0)
printf("0\n");
else if(n==2)
printf("8\n");
else
{
n-=1;
long long ans=((n%mod)*((n+1)%mod)/2)%mod;
long long sum=(ans*ans)%mod;
sum=(sum*8)%mod;
printf("%lld\n",sum);
}
}
return 0;
}