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(T1e5) . 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(0n1e18).

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
0
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 (nk+1)3个边长为k的正方体,其中 ( 1 ≤ k ≤ n ) (1 \le k \le n) (1kn)
故而:边长为n的正方体所能找出的所有正方体共有 ∑ ( n − k + 1 ) 3 \sum(n-k+1)^3 (nk+1)3
因此所求答案就是 8 ∗ ∑ ( n − k + 1 ) 3 8*\sum(n-k+1)^3 8(nk+1)3取模后的结果。

立方求和公式:
在这里插入图片描述

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;
	}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值