美容院网站模板,集团网页建设,徐州新沂网站建设,彩票网站建设教程题目描述
求 a 乘 b 对 p 取模的值#xff0c;其中 1≤a,b,p≤1018。
输入描述:
第一行a#xff0c;第二行b#xff0c;第三行p。
输出描述:
一个整数#xff0c;表示abmodp的值。
示例1
输入
2
3
9
输出
6
#includebits/stdc.h
using namespace std;
t…
题目描述
求 a 乘 b 对 p 取模的值其中 1≤a,b,p≤1018。
输入描述:
第一行a第二行b第三行p。
输出描述:
一个整数表示a×bmodp的值。
示例1
输入
2
3
9
输出
6
#includebits/stdc.h
using namespace std;
typedef long long ll;
typedef pairint,int PII;
const int mod1e97;
const int M4e410;
const int N1e510;
const int INF0x3f3f3f3f;
int minn0x3f3f3f3f;
int maxn0xc0c0c0c0;
int dx[4]{0,0,1,-1};
int dy[4]{1,-1,0,0};
ll n,m,s,e,k,h,a,b,l,r,x,p;
ll qpow(ll a,ll b,ll p)
{ll ans0;while(b){if(b1)ans(ansa)%p;aa*2%p;b1;}return ans;
}
void solve()
{cinabp;coutqpow(a,b,p)endl;
}
int main()
{ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);ll t1;
// cint;while(t--){ solve();}return 0;
}
题目描述
求 a 的 b 次方对 p 取模的值其中0≤a,b,p≤109p0
输入描述:
三个用空格隔开的整数a,b和p。
输出描述:
一个整数表示abmodp的值。
示例1
输入
2 3 9
输出
8
#includebits/stdc.h
using namespace std;
typedef long long ll;
typedef pairint,int PII;
const int mod1e97;
const int M4e410;
const int N1e510;
const int INF0x3f3f3f3f;
int minn0x3f3f3f3f;
int maxn0xc0c0c0c0;
int dx[4]{0,0,1,-1};
int dy[4]{1,-1,0,0};
ll n,m,s,e,k,h,a,b,l,r,x,p;
ll qpow(ll a,ll b,ll p)
{ll ans(ll)1%p;while(b){if(b1)ansans*a%p;aa*a%p;b1;}return ans;
}
void solve()
{cinabp;coutqpow(a,b,p)endl;
}
int main()
{ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);ll t1;
// cint;while(t--){ solve();}return 0;
}