运行 ❯
获取您
自己的
网站
×
更改方向
更改主题,深色/浅色
前往 Spaces
Python
C
Java
def gcd_division(a, b): while b != 0: remainder = a % b print(f"{a} = {a//b} * {b} + {remainder}") a = b b = remainder return a a = 120 b = 25 print("The Euclidean algorithm using division:\n") print(f"The GCD of {a} and {b} is: {gcd_division(a, b)}") #Python
#include <stdio.h> int gcdDivision(int a, int b) { while (b != 0) { int remainder = a % b; printf("%d = %d * %d + %d\n", a, a / b, b, remainder); a = b; b = remainder; } return a; } int main() { int a = 120; int b = 25; printf("The Euclidean algorithm using division:\n\n"); printf("The GCD of %d and %d is: %d\n", a, b, gcdDivision(a, b)); return 0; } //C
public class Main { public static int gcdDivision(int a, int b) { while (b != 0) { int remainder = a % b; System.out.println(a + " = " + (a / b) + " * " + b + " + " + remainder); a = b; b = remainder; } return a; } public static void main(String[] args) { int a = 120; int b = 25; System.out.println("The Euclidean algorithm using division:\n"); System.out.println("The GCD of " + a + " and " + b + " is: " + gcdDivision(a, b)); } } //Java
Python 结果
C 结果
Java 结果
使用除法的欧几里德算法
120 = 4 * 25 + 20
25 = 1 * 20 + 5
20 = 4 * 5 + 0
120 和 25 的最大公约数是:5
使用除法的欧几里德算法
120 = 4 * 25 + 20
25 = 1 * 20 + 5
20 = 4 * 5 + 0
120 和 25 的最大公约数是:5
使用除法的欧几里德算法
120 = 4 * 25 + 20
25 = 1 * 20 + 5
20 = 4 * 5 + 0
120 和 25 的最大公约数是:5