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 @ 2022-05-28 17:01  嘿,抬头!  阅读(36)  评论(0)    收藏  举报