gym 101981 G Pyramid 思维

题意

给我们一个边长为n的正三角形,这个三角形由 n ( n + 1 ) 2 \frac{n*(n+1)}{2} 个单位边长正三角形组成(下图黑色三角形)在这里插入图片描述
对于一个边长为i的三角形,他在边长为n的三角形里面有 ( n i + 1 ) ( n i + 2 ) 2 \frac{(n-i+1)*(n-i+2)}{2}
对于一个边长为i的三角形,除了本身外,各边之间可以组成(i-1)个三角形,故提供i个
所以答案为 i = 1 n ( n i + 1 ) ( n i + 2 ) 2 i = n 4 + 6 n 3 + 11 n 2 + 6 n 24 = C n + 3 4 \sum_{i=1}^{n}\frac{(n-i+1)(n-i+2)}{2}*i=\frac{n^4+6n^3+11n^2+6n}{24}=C_{n+3}^{4}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template <typename T>
void out(T x) { cout << x << endl; }
ll fast_pow(ll a, ll b, ll p) {ll c = 1; while(b) { if(b & 1) c = c * a % p; a = a * a % p; b >>= 1;} return c;}
ll exgcd(ll a, ll b, ll &x, ll &y) { if(!b) {x = 1; y = 0; return a; } ll gcd = exgcd(b, a % b, y, x); y-= a / b * x; return gcd; }
const int mod = 1e9 + 7;
int main()
{
    int t;
    scanf("%d", &t);
    ll inv24 = fast_pow(24, mod - 2, mod);
    while(t --)
    {
        ll n;
        scanf("%lld", &n);
        n = n * (n + 1) % mod * (n + 2) % mod * (n + 3) % mod * inv24 % mod;
        printf("%lld\n", n);
    }
}
发布了76 篇原创文章 · 获赞 5 · 访问量 1309

猜你喜欢

转载自blog.csdn.net/qq_43101466/article/details/102771904