码迷,mamicode.com
首页 > 其他好文 > 详细

有理数取余

时间:2019-10-07 21:48:17      阅读:113      评论:0      收藏:0      [点我收藏+]

标签:sdi   print   nbsp   mes   inline   void   https   style   line   

dalao原文  https://www.luogu.org/blog/cicos/solution-p2613

 

#include <bits/stdc++.h>
using namespace std;

const int MOD = 19260817;//MOD是题解中的"p"
int x, y;

inline int getint(){
    int res = 0, ch = getchar();
    while(!isdigit(ch) and ch != EOF)
        ch = getchar();
    while(isdigit(ch)){
        res = (res << 3) + (res << 1) + (ch - 0);
        res %= MOD;//直接对MOD取余
        ch = getchar();
    }
    return res;
}
void exgcd(int a, int b){
    if(b == 0){
        x = 1;
        y = 0;
        return;
    }
    exgcd(b, a % b);
    int Last_x = x;
    x = y;
    y = Last_x - a / b * y;
}
int main(){
    int a, b;
    a = getint();
    b = getint();
    if(b == 0){
        puts("Angry!");
        return 0;
    }
    exgcd(b, MOD);
    x = (x % MOD + MOD) % MOD;
    printf("%lld\n", a * (long long)(x) % MOD);//小心相乘后爆int
}

 

有理数取余

标签:sdi   print   nbsp   mes   inline   void   https   style   line   

原文地址:https://www.cnblogs.com/aprincess/p/11632021.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!