1. 程式人生 > >p1434 [noip2012]day2-T1同餘方程

p1434 [noip2012]day2-T1同餘方程

題目

https://www.luogu.org/problemnew/show/P1082

程式碼

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a, b, x, y;
inline ll read()
{
	ll f=1,num=0;
	char ch=getchar();
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	while (ch>='0'&&ch<='9'
) num=(num<<1)+(num<<3)+ch-'0',ch=getchar(); return num*f; } void gcd(ll a,ll b,ll &x,ll &y) { if (!b) { x=1,y=0; return; } gcd(b,a%b,x,y); ll tmp=x; x=y; y=tmp-a/b*y; } int main() { a=read(),b=read(); gcd(a,b,x,y); x = (x%b+b)%
b; printf("%lld\n",x); return 0; }