2021“MINIEYE杯”中國大學生算法設計超級聯賽(2)(1001 I love cube)(數學)

傳送門

對於邊長爲1的立方體,滿足題目中的等邊三角形的頂點類似於(0,0,0)(1,1,0),(0,1,1)。

對於邊長爲i的立方體,對答案的貢獻爲$8*(n-i)^3 $

最後答案爲$ \sum_{i=1}^{n-1} 8*(n-i)^3=8\times \sum_{i=1}^{n-1} i^3=2\times(n(n-1)) ^2$


#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
#define rep(i,a,b) for(int i=a;i<=b;i++)
int a[N];
const int mod=1e9+7;
typedef long long LL;
LL mul(LL a,LL b)
{
    return (a%mod)*(b%mod)%mod;
}
LL qmi(LL a,LL b)
{
    LL res=1;
    while(b)
    {
        if(b&1) res=mul(res,a);
        a=mul(a,a);
        b>>=1;
    }
    return res;

}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
    LL n;
    cin>>n;
    if(n%2)
    {
        LL temp=mul(n,(n-1)/2);
        LL res=mul(8,mul(temp,temp));
        printf("%lld\n",res);
    }
    else
    {
         LL temp=mul(n/2,n-1);
         LL res=mul(8,mul(temp,temp));
        printf("%lld\n",res);
    }

    }
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章