其他分享
首页 > 其他分享> > P1082 同余方程(扩欧模板)

P1082 同余方程(扩欧模板)

作者:互联网

https://www.luogu.org/problem/P1082

#include <iostream>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#define inf 2147483647
#define N 1000010
#define p(a) putchar(a)
#define For(i,a,b) for(int i=a;i<=b;++i)

using namespace std;
int a,b,x,y;
void in(int &x){
    int y=1;char c=getchar();x=0;
    while(c<'0'||c>'9'){if(c=='-')y=-1;c=getchar();}
    while(c<='9'&&c>='0'){ x=(x<<1)+(x<<3)+c-'0';c=getchar();}
    x*=y;
}
void o(int x){
    if(x<0){p('-');x=-x;}
    if(x>9)o(x/10);
    p(x%10+'0');
}

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

int main(){
    in(a);in(b);
    exgcd(a,b,x,y);
    o((x%b+b)%b);
    return 0;
}

 

标签:10,return,int,exgcd,同余,P1082,include,扩欧,define
来源: https://www.cnblogs.com/war1111/p/11297257.html