多校联赛二之签到题 I love cube HDU - 6961(找规律)

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的正方体能画出多少个等边三角形

思路:

等边三角形画法如下

在这里插入图片描述
边长为1的三角形可以画出8个等边三角形

边长为n的正方体可以分为边长为1的正方体,边长为2的正方体…边长为n的正方体,一个正方体可以画出8个等边三角形

所以我们需要计算一共可以分为多少个正方体?

边长为n的正方体可以分为n * n * n个边长为1的正方体
边长为n的正方体可以分为(n-1)*(n-1) *(n-1)个边长为2的正方体,以此类推

边长为n的正方形一共可以分为∑(i=0)~(i=n-1)((n-i) ^3) ,由公式得最终结果为(n*(n+1)/2) ^ 2

注意题目给的正方体边长是n-1

代码:

#include<bits/stdc++.h>
using namespace std;
int mod=1000000007;
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        long long n;
        scanf("%lld",&n);
        if(n==0)
            printf("0\n");
        else if(n==2)
            printf("8\n");
        else
        {
            n-=1;
            long long ans=((n%mod)*((n+1)%mod)/2)%mod;
            long long sum=(ans*ans)%mod;
            sum=(sum*8)%mod;
            printf("%lld\n",sum);
        }
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值