bzoj1008[HNOI2008]越狱

快速幂练习题m^n-m*(m-1)^(n-1)最开始脑残把n和m开成int完全不知道哪里错了额呜

#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#define LL long long
#define fo(i,a,b) for (int i=a;i<=b;i++)
using namespace std;
LL read()
{
        LL d=0,f=1;char s=getchar();
        while (s<'0'||s>'9'){if (s=='-')f=-1;s=getchar();}
        while (s>='0'&&s<='9'){d=d*10+s-'0';s=getchar();}
        return d*f;
}
const LL mod=100003;
LL n,m;
 
LL po(LL a,LL b)
{
        if (b==0) return 1;
        if (b==1) return a%mod;
        LL t=po(a,b/2);
        t=(t*t)%mod;
//        cout<<a<<' '<<b<<' '<<t<<endl;
        if (b%2==0) return t;
        else return (t*a)%mod;
}
 
int main()
{
//        cout<<po(2,9)<<endl;cout<<endl;
        m=read(),n=read();
        LL ans=po(m,n)%mod;
        ans=ans+mod;
        ans=(ans-m*po(m-1,n-1)%mod)%mod;
        cout<<ans<<endl;
        return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值