Determinant:求行列式技巧

参考博客:https://www.cnblogs.com/wuanran/p/13907357.html
题目链接:https://ac.nowcoder.com/acm/contest/7502/D

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <string.h>
#include <cmath>
#include <bitset>
#include <set>
#include <map>
#include <list>
#define ll long long
const int inf = 0x3f3f3f3f;
const int mod = 1e9+7;
const ll ds = 1e15+7;
const double p = 3.141592653589793238462643383;

using namespace std;

ll a[100005],b[100005];
ll qpow(ll h,ll g)
{
    ll res = 1;
    while(g){
        if(g & 1) res = (res * h) % mod;
        g >>= 1;
        h = (h * h) % mod;
    }
    return res;
}

int main()
{
    ll n,x;
    while(~scanf("%lld%lld",&n,&x)){
        for(int i = 1; i <= n; i++) scanf("%lld",&a[i]);
        for(int i = 1; i <= n; i++) scanf("%lld",&b[i]);
        ll ans = qpow(x,n-1);
        ll res = (ans*x) % mod;
        ll t = 0;
        for(int i = 1; i <= n; i++){
            t = (t + a[i]*b[i]) % mod;
        }
        ans = (res + ans*t) % mod;
        printf("%lld\n",ans);
    }
    return 0;
}
全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务