bzoj1008[HNOI2008]越狱
2015-11-29 11:30
351 查看
快速幂练习题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;
}
#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;
}
相关文章推荐
- 1.m分解阶乘之和
- 2.几种递推数
- 3.欧拉函数
- 4.快速幂模m算法
- 5.扩展欧几里得&&中国剩余定理
- 6.数论_web
- Project Euler Problem 387 - Harshad Numbers - 深度优先
- 编程之美2015初赛A
- 数论题集
- 原根
- 阶与原根学习笔记
- HDU 1299 Diophantus of Alexandria
- Leftmost Digit(HDU 1060)
- Rightmost Digit(HDU 1061)
- Python-在奇数中寻找素数
- ZOJ 2674 Strange Limit 欧拉定理
- LeetCode-Palindrome Number
- 组合数求模总结
- 【数论】组合数求模
- [BZOJ1041][HAOI2008][数学乱搞]圆上的整点