2018南京ICPC-G

题目:Pyramid

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 10^9 + 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 10^9 + 7.

Example

在这里插入图片描述

思路:

画了边长为4,5,6的三角形,去找规律,发现要用到高阶差分数列,然后套下公式就好
在这里插入图片描述
计算有些复杂,直接给出最后的公式,然后求个逆元,公式套一下就可

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod=1e9+7;
ll q(ll a,ll b){
	ll c=1;
	while(b>0){
		if(b&1)
		c=c*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return c%mod;
}
int main(){
	int t;
	ll x=q(24,mod-2);
	ll y=q(4,mod-2);
	scanf("%d",&t);
	for(int i=1;i<=t;i++){
		int a;
		scanf("%d",&a);
		ll b=1ll*(q(a,4)+11*q(a,2))*x%mod+1ll*(q(a,3)+a)*y%mod;
		printf("%lld\n",b%mod);
	}
} 
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值