同余方程(NOIP2012)

原题传送门

水~

纯拓展欧几里得算法。。

#include<iostream> 
#include<cstdio> 
#define ll long long 
using namespace std; 
ll ans; 
int a,b; 
void exgcd(int a,int b,int &x,int &y) 
{ 
    if(b==0){x=1;y=0;return;} 
    exgcd(b,a%b,x,y); 
    int t=x;x=y,y=t-a/b*y; 
} 
int main() 
{ 
    cin>>a>>b; 
    int x,y; 
    exgcd(a,b,x,y); 
    x=(x%b+b)%b; 
    cout<<x<<endl; 
    return 0; 
} 
原文地址:https://www.cnblogs.com/ghostfly233/p/6831007.html