P2613 【模板】有理数取余 · znzryb
## 思路讲解

由于p给你的一般是素数,一般不用担心b,p互素的问题,除非b%p=0
## AC代码
[https://www.luogu.com.cn/record/192866597](https://www.luogu.com.cn/record/192866597)
```cpp
#include <iostream>
#include <cstring>
#include <algorithm>
#include <deque>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <bitset>
#include <iterator>
#include <random>
#include <iomanip>
#include <cctype>
// https://www.luogu.com.cn/problem/P2613
using namespace std;
typedef long long ll;
const ll N=static_cast<ll>(2e5)+10;
const int m=19260817;
void exgcd(ll a,ll b,ll &x,ll &y){
if(!b) x=1,y=0;
else exgcd(b,a%b,y,x),y-=a/b*x;
}
inline ll getll(){
char c=getchar();
ll res=0;
while (!isdigit(c) && c!=EOF) {
c=getchar();
}
while (isdigit(c)) {
res=((res<<3)+(res<<1)+c-'0')%m;
c=getchar();
}
return res;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
//#ifndef ONLINE_JUDGE
// freopen("P2631_1.in", "r", stdin);
//#endif
ll a=getll();
ll b=getll();
if(b==0){
cout<<"Angry!"<<endl;
return 0;
}
ll x,y;
exgcd(b, m, x, y);
cout<<(x*a%m+m)%m<<endl;
//#ifndef ONLINE_JUDGE
// fclose(stdin);
//#endif
return 0;
}
// AC https://www.luogu.com.cn/record/192866597
```
## 心路历程(WA,TLE,MLE……)