P2613 【模板】有理数取余

link

 

题解可参考:https://www.luogu.com.cn/blog/cicos/solution-p2613#

int a,b;
const int mod=19260817;
int x,y;
int getint(){
    char c=getchar();
    int res=0;
    while(!isdigit(c)) c=getchar();
    while(isdigit(c)){
        res=res*10+(c-'0');
        res%=mod;
        c=getchar();
    }
    return res;
}

void exgcd(int a, int b){
    if(b==0){
        x=1;
        y=0;
        return;
    }
    exgcd(b,a%b);
    int tmp=x;
    x=y;
    y=tmp-a/b*y;
}

int main(){
    int a=getint();
    int b=getint();
    if(b==0){
        printf("Angry!\n");
        return 0;
    }
    exgcd(b,mod);
    x=(x%mod+mod)%mod;
    int res=(LL)a*x%mod;
    printf("%d\n",res);
    return 0;
}

 

posted @ 2020-03-29 17:37  feibilun  阅读(143)  评论(0编辑  收藏  举报