扩展欧几里得求方程 ax+by=gcd(a,b) 的解
2017-08-07 15:37
495 查看
/* *********************************************** ┆ ┏┓ ┏┓ ┆ ┆┏┛┻━━━┛┻┓ ┆ ┆┃ ┃ ┆ ┆┃ ━ ┃ ┆ ┆┃ ┳┛ ┗┳ ┃ ┆ ┆┃ ┃ ┆ ┆┃ ┻ ┃ ┆ ┆┗━┓ 马 ┏━┛ ┆ ┆ ┃ 勒 ┃ ┆ ┆ ┃ 戈 ┗━━━┓ ┆ ┆ ┃ 壁 ┣┓┆ ┆ ┃ 的草泥马 ┏┛┆ ┆ ┗┓┓┏━┳┓┏┛ ┆ ┆ ┃┫┫ ┃┫┫ ┆ ┆ ┗┻┛ ┗┻┛ ┆ ************************************************ */ #include <iostream> #include <set> #include <map> #include <stack> #include <cmath> #include <queue> #include <cstdio> #include <bitset> #include <string> #include <vector> #include <iomanip> #include <cstring> #include <algorithm> #include <functional> #define PI acos(-1) #define eps 1e-8 #define inf 0x3f3f3f3f #define debug(x) cout<<"---"<<x<<"---"<<endl typedef long long ll; using namespace std; long long exgcd(long long a, long long b, long long &x, long long &y) { if (b == 0) { x = 1; y = 0; return a; } long long ans = exgcd(b, a % b, x, y); long long temp = x; x = y; y = temp - (a / b) * y; return ans; } int main() { long long a, b, x, y; while (cin >> a >> b) { exgcd(a, b, x, y); cout << x << " " << y << endl; } return 0; } ///通解 ///x=x0+(b/gcd)*t; ///y=y0-(a/gcd)*t; /************************************************ ┆ ┏┓ ┏┓ ┆ ┆┏┛┻━━━┛┻┓ ┆ ┆┃ ┃ ┆ ┆┃ ━ ┃ ┆ ┆┃ ┳┛ ┗┳ ┃ ┆ ┆┃ ┃ ┆ ┆┃ ┻ ┃ ┆ ┆┗━┓ ┏━┛ ┆ ┆ ┃ ┃ ┆ ┆ ┃ ┗━━━┓ ┆ ┆ ┃ AC代马 ┣┓┆ ┆ ┃ ┏┛┆ ┆ ┗┓┓┏━┳┓┏┛ ┆ ┆ ┃┫┫ ┃┫┫ ┆ ┆ ┗┻┛ ┗┻┛ ┆ ************************************************ */
相关文章推荐
- 拓展欧几里得解方程ax+by=gcd(a,b)
- 解决ax+by=c,不定方程(扩展欧几里得)
- 【数论】扩展欧几里得 Ax+By=m 最小的X
- poj 2142 扩展欧几里得解ax+by=c
- Ray Tracing(扩展欧几里得,ax+by=c最小解)
- 数论 - 用扩展欧几里得解模线性方程ax≡b (mod n) + 生理周期
- SGU 106 The equation (GCD·我所理解的扩展欧几里得)
- uva-12169&&hdu-2769-Disgruntled Judge 扩展欧几里得,模线性方程
- poj_2115 C Looooops(模线性方程+扩展欧几里得)
- 扩展欧几里得算法,解模线性方程,解ax+by=c的解集
- POJ 2115 C Looooops 模线性方程(扩展欧几里得)
- 欧几里得扩展方程
- Java实现算法导论中求解模线性方程解(基于最大公约数欧几里得扩展算法)
- 51Nod 1352 集合计数 (扩展欧几里得求方程解的个数)
- ZOJ3593扩展欧几里得之线性方程
- gcd欧几里得,线性模方程
- 拓展欧几里得-求AX+BY=C中X和Y的值
- The Balance(扩张欧几里得求线性方程ax+by=c或模线性方程ax=b (mod n)的完善模板)
- 1200同余方程{扩展欧几里得}
- 欧几里得gcd+扩展欧几里得exgcd模板