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即可。
。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;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 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框架的用法!