uva10104 - Euclid Problem
来源:互联网 发布:mac 日历 广告 编辑:程序博客网 时间:2024/05/01 09:51
Euclid Problem
The Problem
From Euclid it is known that for any positive integers A and B there exist such integers X and Y thatAX+BY=D, where D is the greatest common divisor of A and B. The problem is to find for given A and Bcorresponding X, Y and D.
The Input
The input will consist of a set of lines with the integer numbers A and B, separated with space (A,B<1000000001).
The Output
For each input line the output line should consist of three integers X, Y and D, separated with space. If there are several such X and Y, you should output that pair for which |X|+|Y| is the minimal (primarily) andX<=Y (secondarily).
Sample Input
4 617 17
Sample Output
-1 1 20 1 17
#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <algorithm>using namespace std;#define ll long longll A , B , D , X , Y;ll gcd(ll a , ll b){ if(b == 0){ X = 1; Y = 0; return a; }else{ ll t = gcd(b , a%b); ll tX = Y; Y = X-(a/b)*Y; X = tX; return t; }}void computing(){ int T = false; if(A < B){ T = true; swap(A , B); } D = gcd(A , B); if(T) swap(X , Y); cout << X << " " << Y << " " << D << endl;}int main(){ while(cin >> A >> B){ computing(); } return 0;}
0 0
- uva10104 - Euclid Problem
- uva10104
- Euclid Problem-ACM
- 10104 - Euclid Problem
- UVA 10104 - Euclid Problem
- uva 10104 - Euclid Problem
- 110703 Euclid problem
- Euclid Problem - PC110703
- UVa 10104 - Euclid Problem
- UVA, 10104 Euclid Problem
- UVa Problem Solution: 10104 - Euclid Problem
- PC/UVa 题号: 110703/1014 Euclid Problem
- (挑战编程_7_3)Euclid problem
- Euclid
- UVa Problem 10104 Euclid Problem (欧几里德问题)
- Uva 10104 Euclid Problem |x|+|y|最小解 扩展欧几里得
- uva 10104 Euclid Problem (数论-扩展欧几里德)
- hdoj problem 1525 Euclid's Game (博弈问题(寻找关键点))
- android基础03:eclipse快捷键
- 【Matlab编程】matlab 画图
- 获取网页源码
- GitHub详细教程
- SQL Server 2008字段精确度
- uva10104 - Euclid Problem
- win7下修改mysql5.0 root 密码
- Android开发之Navigationdrawer导航抽屉功能的实现(源代码分享)
- python中关于时间的处理
- android数据存储(一)之Shared Preferences及注意事项
- android网络编程——使用Android中的网络连接
- 搜狐一题面试题 链表的排序
- OCP 1Z0 051 149
- 温家宝在河北省兴隆县六道河中学作地理讲座