题目: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);
}
}