HDU1576

乘法逆元模板题
#include<iostream>
#define ll long long
using namespace std;
const int mod=9973;
ll A,B,T;
ll power(ll a,ll b,ll p)
{
ll ans=1%p;
for(;b;b>>=1)
{
if(b&1)
{
ans=(ll)ans*a%p;
}
a=(ll)a*a%p;
}
return ans;
}
int main()
{
cin>>T;
while(T--)
{
cin>>A>>B;
cout<<(A*power(B,mod-2,mod))%mod<<endl;
}
return 0;
}
本文详细介绍了HDU1576题目中乘法逆元的解决方法,通过C++实现了一个高效的算法来计算模意义下的乘法逆元。使用快速幂算法来提高效率,适用于竞赛编程中涉及模运算的问题。
1万+

被折叠的 条评论
为什么被折叠?



