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;
}


你可能感兴趣的:(数论)