#include<iostream> #include<cstdlib> #include<cstdio> #include<cmath> #include<cstring> #include<iomanip> #include<algorithm> #include<queue> #include<ctime> #define ll long long #define rg register using namespace std; ll a,b,x,y; inline int read() { int s=0,m=1;char ch=getchar(); while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar(); if(ch=='-')m=-1,ch=getchar(); while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=getchar(); return s*m; } void exgcd(ll a,ll b,ll &x,ll &y) { if(!b) { x=1;y=0;return; } else { exgcd(b,a%b,y,x);y-=x*(a/b); } } int main() { a=read();b=read(); exgcd(a,b,x,y); x=(x%b+b)%b; cout<<x<<endl; return 0; }
luoguP1082 同余方程 题解(NOIP2012)(数论)
猜你喜欢
转载自www.cnblogs.com/cjoierljl/p/9074506.html
今日推荐
周排行