110703 Euclid problem

原创 2013年12月05日 17:56:49


import java.util.*;

public class Main {
	
	private static void EuclidAlgorithm(int a, int b)
	{
		if (a < b)
		{
			EuclidAlgorithm(b, a);
			int temp = ResultX;
			ResultX = ResultY;
			ResultY = temp;
			return;
		}
		
		if (b == 0)
		{
			ResultX = 1;
			ResultY = 0;
			ResultGCD = a;
			return;
		}
		
		int floor = a / b;
		EuclidAlgorithm(b, a - b * floor);
		int tempX = ResultX;
		int tempY = ResultY;
		ResultX = tempY;
		ResultY = tempX - tempY * floor;
		return;
	}
	
	private static void OutputEuclidNumbers(int a, int b)
	{
		EuclidAlgorithm(a, b);
		System.out.println(ResultX + " " + ResultY + " " + ResultGCD);
	}
	
	public static void main(String[] args){
		Scanner inScanner = new Scanner(System.in);
		while(inScanner.hasNextInt())
		{
			int a = inScanner.nextInt();
			int b = inScanner.nextInt();
			OutputEuclidNumbers(a, b);
		}
	}
	
	private static int ResultX;
	private static int ResultY;
	private static int ResultGCD;
}


版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

Uva 10104 Euclid Problem |x|+|y|最小解 扩展欧几里得

/* * url: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p...

UVa Problem 10104 Euclid Problem (欧几里德问题)

// Euclid Problem (欧几里德问题)// PC/UVa IDs: 110703/10104, Popularity: A, Success rate: average Level: 1...

证明:gcd(m,n)=gcd(n mod m,m)成立,m,n为正整数,m>0. 【Euclid算法证明】

--本文证明部分转载自:   http://www.cnblogs.com/ider/archive/2010/11/16/gcd_euclid.html   作者:  Ider  网上证明...

HDU4993 Revenge of ex-Euclid

Revenge of ex-Euclid Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/O...

euclid几何原本

  • 2008-03-03 10:47
  • 9.36MB
  • 下载

euclid algorithm(greast common divisor)

#include using namespace std; void swap(int &a, int &b) { int tmp; tmp = a; a = b; ...

euclid algorithmjava

euclid algorithm

内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)