1. 程式人生 > >hdu_6050: Funny Function (2017 多校第二場 1006) 【找規律】

hdu_6050: Funny Function (2017 多校第二場 1006) 【找規律】

name sin target blank 找規律 png pan center .com

題目鏈接

暴力打個表找下規律就好了,比賽時看出規律來了倒是,然而看這道題看得太晚了,而且高中的那些數列相關的技巧生疏了好多,然後推公式就比較慢。。其實還是自身菜啊。。

公式是

技術分享

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;

const LL mod=1e9+7; 
LL qpow(LL x,LL n)        //求x^n%mod 
{
    LL ret=1;
    for(; n; n>>=1)
    {
        if(n&1) ret=ret*x%mod;
        x
=x*x%mod; } return ret; } LL inv(LL x) { return qpow(x,mod-2); } int T; LL n,m; LL ans; int main() { scanf("%d",&T); while(T--) { scanf("%lld%lld",&n,&m); if(n&1) ans=(qpow(qpow(2,n)-1,m-1)*2%mod+1)*inv(3)%mod; else ans=qpow(qpow(2
,n)-1,m-1)*2%mod*inv(3)%mod; printf("%lld\n",ans); } }

hdu_6050: Funny Function (2017 多校第二場 1006) 【找規律】