#include<stdio.h>
int gcd(int data1, int data2) {
if (data1 > data2 && data1 % data2 == 0) {
return data2;
}
return gcd(data2, data1%data2);
}
int main(){
int num1,num2;
int temp;
scanf("%d%d",&num1,&num2);
if (num1 < num2) {
temp = num1;
num1 = num2;
num2 = temp;
}
int result = gcd(num1, num2);
int i, j;
for (i = 1; ; i++) {
if ((result - num2*i) % num1 == 0) {
printf("(%d * %d) + (%d * %d) = %d\n", num2, i, num1, (result - num2*i)/num1, result);
return 0;
}
}
printf("%d", result);
return 0;
}
将两个正整数的最大公约数表示成两个数的线性组合, data1 * n + data2 *m = gcd(data1, data2)
最新推荐文章于 2024-09-19 21:13:13 发布