一.a^b%c
1.题意:
2.题解:
3.ac代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll quick_pow(ll a,ll b,ll c) {
ll ans = 1;
while(b) {
if(b&1)
ans = (ans * a) % c;
a = (a*a) % c;
b >>= 1;
}
return ans%c;
}
int main(){
ll a,b,p;
ll ans;
while(cin>>a>>b>>p){
ans=quick_pow(a,b,p);
cout<<ans<<endl;
}
}
二.快速幂取模
1.题意:
2.题解:
(A1B1+A2B2+ … +AHBH)mod M.
3.ac代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll quick_pow(ll a,ll b,ll c) {
ll ans = 1;
while(b) {
if(b&1)
ans = (ans * a) % c;
a = (a*a) % c;
b >>= 1;
}
return ans%c;
}
int main(){
int t;
ll m,a,b;
ll ans;
while(cin>>t){
while(t--){
ans=0;
cin>>m;
int h;
cin>>h;
while(h--){
cin>>a>>b;
ans=(ans+quick_pow(a,b,m))%m;
}
cout<<ans<<endl;
}
}
}
三.64位整数乘法
1.题意:
2.题解:
3.ac代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll quick_mul(ll a, ll b, ll c) {
ll ans = ((long double) a * b + 0.5) / c;
return ((a * b - ans * c) % c + c) % c;
}
int main(){
ll a,b,p;
ll ans;
while(cin>>a>>b>>p){
ans=quick_mul(a,b,p);
cout<<ans<<endl;
}
}
四.状态压缩dp
1.题意:
2.题解:
3.ac代码:
在这里插入代码片