天天看点

HDUOJ -I love cube

题目链接:https://acm.hdu.edu.cn/showproblem.php?pid=6961

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 ≤ 1 e 5 ) T(T \le 1e5) T(T≤1e5) . Then T test cases follow.

Each test case contains a single Integer n ( 0 ≤ n ≤ 1 e 18 ) n(0 \le n \le 1e18) n(0≤n≤1e18).

If n=0, output 0

Output

For each case, print an integer, which is the answer modulo 1 0 9 + 7 10^9+7 109+7

Sample Input

2

1

2

Sample Output

8

题目大意:给定一个整数n,表示有一个边长为n-1的立方体,其各个面都平行于空间直角坐标系下的Oxy、Oxz、Oyz某一个平面,其有一个顶点处于坐标(0,0,0)处,请问你可以在正方体范围内找到多少个顶点处于整数坐标处,且每一边都与某一个坐标面平行的正三角形?答案对1e9+7取模。

思路:对于边长为1的正方体,可以找到8个符合的正三角形。

设A为:以边长为1的正方体作为基本单位,堆砌而成的大正方体,那么其内部所具有的所有的正方体都可以找出8个不同的正三角形,且顶点皆处于整数坐标处。

对于边长为n的正方体A,可以找到 ( n − k + 1 ) 3 (n-k+1)^3 (n−k+1)3个边长为k的正方体,其中 ( 1 ≤ k ≤ n ) (1 \le k \le n) (1≤k≤n)

故而:边长为n的正方体所能找出的所有正方体共有 ∑ ( n − k + 1 ) 3 \sum(n-k+1)^3 ∑(n−k+1)3个

因此所求答案就是 8 ∗ ∑ ( n − k + 1 ) 3 8*\sum(n-k+1)^3 8∗∑(n−k+1)3取模后的结果。

立方求和公式:

HDUOJ -I love cube

AC代码:

#include<iostream>
#include<cstdio>
const int maxn = 100005;
const long long mod = 1e9 + 7;
using namespace std;
int main(void) {
	int t; cin >> t;
	while (t--) {
		long long n; cin >> n;
		n--;
		n %= mod;
		long long ans = 0;
		ans += 2 * ((((n * n % mod) * n) % mod) * n) % mod;
		ans += (4 * ((n * n) % mod) * n) % mod;
		ans += 2 * n * n;
		ans %= mod;
		cout << ans << endl;
	}
}