您的位置:首页 > 其它

bzoj1008[HNOI2008]越狱

2015-11-29 11:30 295 查看
快速幂练习题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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  数论