[洛谷P2613][模版]有理数取余:乘法逆元

分析:

看着标签里有扩欧才点进来的,根本一点关系都没有好不好啊!!!
在read()里随便改改就好。

代码:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <algorithm>
typedef long long LL;

const LL MOD=19260817;

inline LL read(){
    LL x=0;char ch=getchar();
    while(ch<'0'||ch>'9') ch=getchar();
    while(ch>='0'&&ch<='9'){x=((x<<3)+(x<<1)+ch-'0')%MOD;ch=getchar();}
    return x;
}

LL a,b;

inline LL qpow(LL x,LL y){
    LL ret=1,tt=x%MOD;
    while(y){
        if(y&1) ret=ret*tt%MOD;
        tt=tt*tt%MOD;
        y>>=1;
    }
    return ret;
}

int main(){
    a=read(),b=read();
    if(b==0){
        printf("Angry!\n");
        return 0;
    }
    printf("%lld\n",a*qpow(b,MOD-2)%MOD);
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/ErkkiErkko/p/9833512.html