7.22 第二场 I love cube
7.22 第二场 I love cube
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 513 Accepted Submission(s): 206
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
大概题意
立方体边长为n-1
求这个正方体中等边三角形数量(三条边必须平行于Oxy,Oyz,Oxz三个平面之一,三个点必须落在立方体内的整数点上)
思路
找规律
1 0
2 8*(2-1)3
3 8*((3-2)3+(3-1)3)
4 8*((4-3)3+(4-2)3+(4-1)3)
….
n 8*((n-1)3+(n-2)3+……+23+13)8*((3-2)3+(3-1)3)
代码
//
// Created by Black on 2021/7/22.
//
#include <iostream>
#include <cstdio>
using namespace std;
const int MOD = 1e9 + 7;
int t;
long long n;
int main() {
cin >> t;
while (t--) {
cin >> n;
n %= MOD;
if (n == 0) {
cout << 0 << endl;
continue;
}
long long res = 0;
long long temp = (n * (n - 1)) % MOD;
res = (temp * temp) % MOD;
res = (res * 2) % MOD;
int ans = (int) res;
printf("%d\n", ans);
}
return 0;
}
/**
* 1 8
* 2 72
* 3 288
*/
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
· SQL Server 2025 AI相关能力初探
· 为什么 退出登录 或 修改密码 无法使 token 失效