P2613 【模板】有理数取余 代码记录
EXR_FAL
·
·
算法·理论
//Ciallo~(∠・ω< )⌒★
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline ll read(){
ll x=0,flag=1;
char ch=getchar();
while(!isdigit(ch)){
if(ch=='-') flag=-1;
ch=getchar();
}
while(isdigit(ch)){
x=x*10+(ch^48);
ch=getchar();
}
return x*flag;
}
void out(ll x){
if(x<0){
putchar('-');
x=-x;
}
if(x<10)
putchar(x+'0');
else{
out(x/10);
putchar(x%10+'0');
}
}
const int mod=19260817;
ll EX_read(){
ll f=1,res=0,ch=getchar();
while(!isdigit(ch)&&ch!=EOF){
if(ch=='-') f=-1;
ch=getchar();
}
while(isdigit(ch)){
res=(res<<3)+(res<<1)+(ch-'0');
res%=mod;
ch=getchar();
}
return res;
}
ll x,y,a,b;
ll EX_GCD(ll a,ll b,ll &x,ll &y){
if(b==0){
x=1,y=0;
return a;
}
ll d=EX_GCD(b,a%b,y,x);
y-=a/b*x;
return d;
}
ll Ciallo(ll a,ll b,ll mod){
x=0,y=0;
if(b==0) return -1;
EX_GCD(b,mod,x,y);
x=(x%mod+mod)%mod;
return a*x%mod;
}
int main(){
a=EX_read(),b=EX_read();
ll res=Ciallo(a,b,mod);
if(res==-1) puts("Angry!");
else out(res),puts("");
return 0;
}