zoukankan      html  css  js  c++  java
  • 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 imes sum_{i=1}^{n-1} i^3=2 imes(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
    ",res);
        }
        else
        {
             LL temp=mul(n/2,n-1);
             LL res=mul(8,mul(temp,temp));
            printf("%lld
    ",res);
        }
    
        }
    }
    
    
  • 相关阅读:
    Android笔记
    Scala中apply的用法
    MySQL备忘
    Spring test
    Scala
    Dubbo
    Scala元组
    Scala中None, Nil, Nothing的区别
    java多态与异常处理——动手动脑
    《大道至简》第七八章读后感
  • 原文地址:https://www.cnblogs.com/zzyh/p/15063559.html
Copyright © 2011-2022 走看看