使用欧几里得算法计算两个数的最大公约数
来源:互联网 发布:下载录屏软件 编辑:程序博客网 时间:2024/06/04 08:52
public class Gcd {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Please input the first number:");
int m = scanner.nextInt();
System.out.println("Please input the second number:");
int n = scanner.nextInt();
divisor(m, n);
scanner.close();
}
// 使用欧几里得算法计算最大公约数
public static int gcd(int max, int min) {
if (max % min == 0) {
System.out.println("the bigest divisor is:" + min);
return min;
}
return gcd(min, max % min);
}
public static int divisor(int m, int n) {
System.out.println("m:" + m + ", n:" + n);
if (n > m) {
m = m ^ n;
n = m ^ n;
m = m ^ n;
}
System.out.println("m:" + m + ", n:" + n);
return gcd(m, n);
}
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Please input the first number:");
int m = scanner.nextInt();
System.out.println("Please input the second number:");
int n = scanner.nextInt();
divisor(m, n);
scanner.close();
}
// 使用欧几里得算法计算最大公约数
public static int gcd(int max, int min) {
if (max % min == 0) {
System.out.println("the bigest divisor is:" + min);
return min;
}
return gcd(min, max % min);
}
public static int divisor(int m, int n) {
System.out.println("m:" + m + ", n:" + n);
if (n > m) {
m = m ^ n;
n = m ^ n;
m = m ^ n;
}
System.out.println("m:" + m + ", n:" + n);
return gcd(m, n);
}
}
0 0
- 使用欧几里得算法计算两个数的最大公约数
- Java程序实现欧几里得算法-计算两个数的最大公约数
- 欧几里得算法求两个数的最大公约数
- 计算两个非负整数的最大公约数(欧几里得算法)
- 用欧几里得算法实现两个数的最大公约数和最小公倍数
- 求两个数最大公约数,欧几里得算法
- 使用欧几里得算法求两个自然数的最大公约数
- Euclid欧几里得(求两个数的最大公约数)
- 计算两个数的最大公约数
- 计算两个数的最大公约数
- 给定两个数m,n,使用欧几里得的辗转相除法求出它们的最大公约数
- 编程计算两个数的最大公约数
- 计算两个数的最大公约数和最小公倍数
- c++实现用欧几里得算法求两个整数的最大公约数
- 用java实现欧几里得算法求两个数字的最大公约数
- 用欧几里得算法求两个非负整数的最大公约数
- 一个求两个数最大公约数的算法
- 求两个数的最大公约数算法
- 017.View与窗口:AttachInfo
- 汉字转拼音类
- BTY-B1薄膜透气测试
- 浅析Java中的final关键字
- XML序列化和反序列化
- 使用欧几里得算法计算两个数的最大公约数
- Lua 字符串操作,截取指定字符串前后内容,lua 取指定字符左侧,或右侧内容
- iOS开发遇到的问题
- viewpager更新没作用
- linux 下的 tomcat
- vitamio5.x的简单使用(二)
- 【MessageUI】iOS调用 短信 与 邮件
- 嵌入式Linux——编译linux内核
- 一致性哈希算法与Java实现