Pyramid (Gym -01981G)

Problem Description

The use of the triangle in the New Age practices seems to be very important as it represents the unholy trinity (Satan, the Antichrist and the False Prophet bringing mankind to the New World Order with false/distorted beliefs). The triangle is of primary importance in all Illuminati realms, whether in the ritual ceremonies of the Rosicrucians and Masons or the witchcraft, astrological and black magic practices of other Illuminati followers.

One day you found a class of mysterious patterns. The patterns can be classified into different degrees. A pattern of degree n consists of n(n+1)/2 small regular triangles with side length 1, all in the same direction,forming a big triangle. The figure below shows the pattern of degree 3. All small regular triangles are highlighted.

Since the pattern contains many regular triangles, which is very evil and unacceptable, you want to calculate the number of regular triangles formed by vertices in the pattern, so that you can estimate the strength of Illuminati. It is not necessary that each side of regular triangles is parallel to one side of the triangles. The figure below shows two regular triangles formed by vertices in a pattern of degree 3.

Since the answer can be very large, you only need to calculate the number modulo 109 + 7.

Input

The first line contains an integer t (1 ≤ t ≤ 106) — the number of test cases.

Each of the next t lines contains an integer n (1 ≤ n ≤ 109) — the degree of the pattern.

Output

For each test case, print an integer in one line — the number of regular triangles modulo 109 + 7.

Sample Input

3
1
2
3

Sample Output

1
5
15

题意:t 组查询,每组给出一个数 n 代表有 n 行三角形,问存在多少个正三角形

思路:打表找规律,可以发现有 (n-4)*(n-3)*(n-2)*(n-1)/24

Source Program

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#define EPS 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
#define Pair pair<int,int>
const int MOD = 1E9+7;
const int N = 400+5;
const int dx[] = {1,-1,0,0,-1,-1,1,1};
const int dy[] = {0,0,-1,1,-1,1,-1,1};
using namespace std;
LL Pow(LL a,LL b) {
    LL res=1;
    while(b) {
        if(b&1)
            res=res*a%MOD;
        a=a*a%MOD;
        b>>=1;
    }
    return res;
}
int main() {
    LL inv=Pow(24LL,MOD-2LL);//逆元

    int T;
    scanf("%d",&T);
    while(T--) {
        LL x;
        scanf("%lld",&x);
        LL sum = x*x%MOD*x%MOD*x%MOD + x*x%MOD*x%MOD*6LL%MOD + x*x%MOD*11LL%MOD + x*6LL%MOD;
        sum = sum%MOD*inv%MOD;
        printf("%lld\n",sum);
    }
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值