题解 | #小乐乐与欧几里得#
小乐乐与欧几里得
https://www.nowcoder.com/practice/da13e0cf321e4df9acd0fdf0a433cbb0
#include <stdio.h>
int main() {
long a, b,temp,z,l;
scanf("%ld %ld",&a,&b);
l =a*b;
while(a != b){
//确定a 为最大值,b为最小值
if(a<b){
temp = a;
a = b;
b = temp;
}
a = a-b==0?0:a-b;
}
z = l/a;
printf("%ld",z+a);
return 0;
}
//最大公约数
/*
17 5 17-5=12 12-5=8 8-5=3 5-3=2 3-2= 1 2-1=1 1-1=0
7 7 7-7=0
//最小公倍数等于:两数乘积除以最大公约数
*/