注意:最后算的答案还要再%mod一下防止出现1^0modk=1的情况(应该为0)
快速乘
#include<bits/stc++.h>
#define ll long long
using namespace std;
inline ll ksc(ll a, ll b, ll mod){
ll ans = 0;
while( b > 0 ){
if( b&1 ) ans = (ans + a) % mod;
a = ( a + a ) % mod;
b >>= 1;
}
return ans;
}
快速幂
#include<bits/stc++.h>
#define ll long long
using namespace std;
inline ll ksm(ll a, ll b, ll mod){
ll ans = 1;
while( b > 0 ){
if( b&1 ) ans = (ans * a) % mod;
a = ( a * a ) % mod;
b >>= 1;
}
return ans;
}