题目
求最小公倍数_牛客题霸_牛客网 (nowcoder.com)
Python
辗转相除法
dividend,divisor=map(int,input().split()) #被除数,除数
# remainder=0 余数
# 最小公倍数
def lcm(dividend,divisor):# 最大公约数def gcd(dividend,divisor):if 0==divisor:return dividendelse:return gcd(divisor,dividend%divisor)return (dividend*divisor)//(gcd(dividend,divisor))print(lcm(dividend,divisor))
C++
#include <iostream>
using namespace std;int gcd(int dividend, int divisor)
{if (0 == divisor) return dividend;else return gcd(divisor, dividend % divisor);
}
int lcm(int dividend, int divisor)
{return (dividend * divisor) / gcd( dividend, divisor);
}int main() {int a, b;while (cin >> a >> b){// 注意 while 处理多个 casecout<< lcm(a, b)<<endl; }
}
// 64 位输出请用 printf("%lld")
C语言
#include <stdio.h>int gcd(int dividend, int divisor)
{if (0 == divisor) return dividend;else return gcd(divisor, dividend % divisor);
}
int lcm(int dividend, int divisor)
{return (dividend * divisor) / gcd( dividend, divisor);
}int main() {int a, b;while (scanf("%d %d", &a, &b) != EOF){ // 注意 while 处理多个 case// 64 位输出请用 printf("%lld") to //printf("%d\n", a + b);printf("%d", lcm( a, b));}return 0;
}