题解 | #小乐乐与欧几里得#
小乐乐与欧几里得
https://www.nowcoder.com/practice/da13e0cf321e4df9acd0fdf0a433cbb0
#include <stdio.h> int main() { long long int n, m, a=0, max, min; scanf("%lld %lld", &n, &m); /*如果N与M相等,则A为其本身*/ if(n == m) a = n; /*区分N与M哪一个大*//*若N更大,将N-M与MIN想比较,若相等,跳出循环,不等,继续*/ else if(n > m) { max = n; min = m; a = max -min; while(min != a) { if(min > a) { max = min; min = a; } else { max = a; } a = max-min; } } else { max = m; min = n; a = max -min; while(min != a) { if(min > a) { max = min; min = a; } else { max = a; } a = max-min; } } printf("%lld", a+(n*m)/a); return 0; }