分数取模:
参考文章:https://www.cnblogs.com/drperry/p/13448061.html
例题:P5104
(A / B) % modd = ((A % modd) * Pow(B,modd - 2)) % modd;
代码:
#include<bits/stdc++.h>
using namespace std;
long long modd;
long long Pow(long long x,long long k)
{
x%=modd;
long long ans=1;
while(k)
{
if(k&1)
{
ans*=x;
ans%=modd;
}
x*=x;
x%=modd;
k>>=1;
}
return ans;
}
int main()
{
long long a,b;
cin>>a>>b;
cout<<(a*Pow(b,modd-2))%modd<<endl;
return 0;
}
负数取模:
例题:https://ac.nowcoder.com/acm/contest/6357/A
ans%=modd;
ans=modd+ans;