题目大意
给你一个边长为 n − 1 n-1 n−1 的立方体,问你在其中能找出多少个等边三角形,三角形的三条边必须平行于坐标面
解题思路
我们发现一个边长为
1
1
1 的立方体中可以找出
8
8
8 个不同的等边三角形。
那么我们只需要计算有多少个边长为
1
,
2
,
3
,
⋯
,
n
1, 2, 3, \cdots, n
1,2,3,⋯,n 的立方体。
我们发现边长为
1
,
2
,
3
,
⋯
,
n
−
1
1, 2, 3, \cdots, n-1
1,2,3,⋯,n−1 的立方体分别有
(
n
−
1
)
3
,
(
n
−
2
)
3
,
⋯
,
1
3
(n-1)^3, (n-2)^3, \cdots, 1^3
(n−1)3,(n−2)3,⋯,13 个,所以答案就是
8
×
∑
i
=
1
n
−
1
i
3
8 \times \sum_{i=1}^{n-1} i ^3
8×i=1∑n−1i3
Code
#include <bits/stdc++.h>
#define ll long long
#define qc ios::sync_with_stdio(false); cin.tie(0);cout.tie(0)
#define fi first
#define se second
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define pb push_back
using namespace std;
const int MAXN = 2e5 + 7;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll mod = 1e9 + 7;
inline int read()
{
int x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
ll n;
ll qpow(ll x, ll y){
ll ret = 1;
while(y){
if(y&1) ret = ret * x % mod;
x = x * x % mod;
y >>= 1;
}
return ret;
}
void solve(){
cin >> n;
n--;
n %= mod;
cout << ((n+1)*n % mod * qpow(2, mod-2) % mod ) * ((n+1)*n % mod * qpow(2, mod-2) % mod ) % mod * 8 % mod << endl;
}
int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
qc;
int T;
cin >> T;
// T = 1;
while(T--){
solve();
}
return 0;
}