zoukankan      html  css  js  c++  java
  • 有理数取余

    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
    ", a * (long long)(x) % MOD);//小心相乘后爆int
    }
  • 相关阅读:
    join
    PS1-4
    tftp + bras
    awk调用shell
    curl
    ssh
    查看cp进度,使用watch
    tftp
    scp 链接文件的问题 + tar
    mysql必知必会(三、使用mysql)
  • 原文地址:https://www.cnblogs.com/aprincess/p/11632021.html
Copyright © 2011-2022 走看看