多校1006 HDU-6050. Funny Function 数学推导题

大意:给要求 求公式推导。
Function Fx,yFx,ysatisfies:

这里写图片描述

For given integers N and M,calculate Fm,1Fm,1 modulo 1e9+7.
Input
There is one integer T in the first line.
The next T lines,each line includes two integers N and M .
1<=T<=10000,1<=N,M<2^63.
Output
For each given N and M,print the answer in a single line.
Sample Input
2
2 2
3 3
Sample Output
2
33

思路:
纯公式推导题,按照题解思路用矩阵快速幂,然而在比赛的时候我直接把公式全推好了hhh

具体过程归纳有得到这个公式
这里写图片描述
进一步得到:
这里写图片描述

题解是这样的:
这里写图片描述

由图一可以得出等比数列,然后分奇偶,理论上就都能算。
实际上算完,最后结果是这样的:

FM,1=

N2(2N1)M1+13

N2(2N1)M13

除的时候用乘法逆元:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mem(s,t) memset(s,t,sizeof(s))
#define D(v) cout<<#v<<" "<<v<<endl
#define inf 0x3f3f3f3f
//#define LOCAL
const int MAXN =1e5+10;
const int mod=1e9+7;
ll N,x;
ll quick_mod(ll a, ll b){
    ll ret=1;
    a%=mod;
    while(b>0){
        if(b&1){
            ret=(ret*a)%mod;
        } 
        b>>=1;
        a=(a*a)%mod;
    }
    return ret;
}

int main() {
#ifdef LOCAL
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
#endif
    int t;
    scanf("%d",&t);
    while(t--){
        ll ans=0;
        scanf("%lld%lld",&N,&x);
        int a=quick_mod(2,N);
        if(N&1){
            ans=(ll)(((2*quick_mod(a-1,x-1))%mod+1)%mod)*quick_mod(3,mod-2)%mod;
        }else{
            ans=(ll)(((2*quick_mod(a-1,x-1))%mod)%mod)*quick_mod(3,mod-2)%mod;
        }
        printf("%lld\n",ans);
    }
    return 0;
}

PS.这个推导过程其实就相当于把二维的矩阵变为一维来算,而且是手工计算。原因大概是自己矩阵不怎么会做吧,这种题还是比较舒服的,实际上一维形式来推公式速度并不慢,是机房一血。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值