/*
*CopyRight (C)2014, Saluton+, All Rights Reserved.
*Filename:GCDExtension.java
*Author: Saluton+ Version: 1.0 Date: 2014.08.15
*Description: 初等数学导论:欧几里得公式推广,计算最大公约数的线性组合。
*/
public class GCDExtension{
public static Triple gcdExtension(int a, int b){
Triple z = new Triple();
if( b == 0 ){
z.d = a;
z.x = 1;
z.y = 0;
}
else{
Triple t = gcdExtension(b, (a % b));
z.d = t.d;
z.x = t.y;
z.y = t.x - (a / b)*t.y;
}
return z;
}
public static void main(String[] args){
Triple triple = new Triple();
triple = gcdExtension(19,3);
System.out.println("The Result Is:");
System.out.println(triple.d);
System.out.println(triple.x);
System.out.println(triple.y);
}
}
class Triple{
int d;
int x;
int y;
}
初等数学导论:最大公约数的线性组合
最新推荐文章于 2024-08-13 09:17:48 发布