zoukankan      html  css  js  c++  java
  • ZR#1009

    ZR#1009

    解法:

    因为无敌的SR给了一个大暴力算法,所以通过打表发现了了一些神奇的性质,即第一行和第一列的对应位置数值相等。
    我们可以通过手算得出 $ F(n) = frac{n(n + 1)(n + 2)}{6} $
    然后就可以 $ O(1) $ 求出 $ ans = F(n) * F(m) $。

    CODE:

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<cmath>
    
    using namespace std;
    
    #define LL long long
    const int mod = 1e9 + 7;
    
    LL n,m,ans;
    
    inline LL fast_pow(LL a,LL b,LL p) {
        LL ans = 1;
        while(b) {
            if(b & 1) ans = ans * a % p;
            a = a * a % p;
            b >>= 1;
        }
        return ans % p;
    }
    inline LL calc(LL x) {
        return (x % mod * (x + 1) % mod * (x + 2) % mod + mod) % mod * fast_pow(6,mod-2,mod) % mod;
    }
    
    int main() {
        scanf("%lld%lld",&n,&m);
        n %= mod,m %= mod;
        ans = calc(n) % mod * calc(m) % mod;
        printf("%lld
    ",ans);
        //system("pause");
        return 0;
    }
    
  • 相关阅读:
    ff与ie 的关于js兼容性
    CSS清除浮动的方法
    java8 LocalDateTime
    BigDecimal
    JAVA将 Word 文档转换为 PDF
    Ionic4
    SpringBoot后端统一格式返回
    SpringBoot集成JWT
    Java Lombok
    SpringBoot 中通过 CORS 解决跨域问题
  • 原文地址:https://www.cnblogs.com/Repulser/p/11709205.html
Copyright © 2011-2022 走看看