首先说一下矩阵快速幂咱是不会的qwq
另外咱也没写过非递归版的(:з」∠)_
emmmmm…….
快速幂:
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<iostream>
using namespace std;
typedef long long ll;
ll sum,m,n;
ll mod=100000003ll;//超int的数要加上'll'不然会RE
ll poww(ll a,ll b)//怕pow出事情
{
if(b==0) return 1;
if(b==1) return a;
if(b==2) return a*a;
ll tmp=poww(a,b/2);
if(b%2==1) return tmp*tmp*a;
else return tmp*tmp;//各种膜
}
inline void write(ll x)
{
if(x < 0)
putchar('-'),x *= -1;
if(x / 10)
write(x / 10);
putchar(x % 10 + '0');
}
int main()
{
cin>>n>>m;
write( poww(n,m) );
return 0;
}
但是快速幂太容易华丽丽炸上天了
因此,**发动力量优化
下面的是膜法之力
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<iostream>
using namespace std;
typedef long long ll;
ll sum,m,n;
ll mod=100000003ll;//超int的数要加上'll'不然会RE
ll poww(ll a,ll b)//怕pow出事情
{
if(b==0) return 1;
if(b==1) return a;
ll t=b>>1;
ll x=poww(a,t);
ll ans=( (x%mod)*(x%mod) )%mod;
if(b&1)//位运算效果是如果b为奇数
ans=( (ans%mod)*(a%mod) )%mod;//膜法原理【滑稽
return ans%mod;//各种膜
}
inline void write(ll x)
{
if(x < 0)
putchar('-'),x *= -1;
if(x / 10)
write(x / 10);
putchar(x % 10 + '0');
}
int main()
{
cin>>n>>m;
write( poww(n,m) );
return 0;
}