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
*/
posted @   嘿,抬头!  阅读(25)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
· SQL Server 2025 AI相关能力初探
· 为什么 退出登录 或 修改密码 无法使 token 失效
点击右上角即可分享
微信分享提示