P1082 [NOIP2012 提高组] 同余方程

/*
3 10

7

*/
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<bits/stdc++.h>
#define ll long long
#define ddd printf("-----------------debug\n");
using namespace std;

int x,y,a,b;
void exgcd(int a,int b,int &x,int &y)
{
    if(b==0){ x=1;y=0; return;}
    exgcd(b,a%b,y,x);
    y-=(a/b)*x;
}
int main()
{
    ios::sync_with_stdio(false);
    cin>>a>>b;
    exgcd(a,b,x,y);
    cout<<(x%b+b)%b<<endl;
    
    return 0;
}
View Code

 

posted @ 2023-07-12 20:20  JMXZ  阅读(22)  评论(0)    收藏  举报