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\n",ans);
    //system("pause");
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/Repulser/p/11709205.html