def solution(*args) -> int:
if len(args) == 1:
return args[0]
sum = max(args)
for a in args:
if sum % a == 0:
continue
sum *= a
min_cm = 0
while (sum > 0):
flag = True
for a in args:
if sum % a !=0:
flag = False
break
if flag:
min_cm = sum
sum -= 1
return min_cm
assert solution(2,3,4) == 12
assert solution(2,5) == 10
assert solution(9) == 9
assert solution(2,4) == 4
def solution(*args) -> int:
size = len(args)
idx = 1
i = args[0]
f = 0 # 给定初始化结果
if size == 1: # 如果长度为1,则最大公倍数为i
return i
while idx < size:
j = args[idx]
b = i if i < j else j
a = i if i > j else j
while a != 0: # 使用欧几里得公式求两个数的最大公约数 b
a, b = b % a, a
f = int(i * j / b) # 最小公倍数=两数相乘/最大公约数
i = f # 阶段性得出来最大公倍数用于与下一个数字进行计算最大公倍数
idx += 1
return f
#累加法
def solution(*args) -> int:
if args == ():
return
if len(args) == 1:
return args[0]
mul = 1
for i in args:
mul *= i
j = max(args)
while max(args) <= j <= mul:
flag = True
for i in args:
if j % i != 0:
flag = False
if flag == True:
return j
j += 1
assert solution(2, 3, 4) == 12
assert solution(2, 5) == 10
assert solution(9) == 9
assert solution(3) == 3
# 辗转相减法求最大公因数
def solution(*args) -> int:
if len(args) == 0:
return -1
new_list = []
for i, i_value in enumerate(args):
for j_value in args[i + 1:]:
tmp = 1
mi = min(i_value, j_value)
ma = max(i_value, j_value)
while tmp != 0:
tmp = ma - mi
if tmp > mi:
ma = tmp
else:
ma = mi
mi = tmp
new_list.append(ma)
mu, p = 1, 1
for i in new_list:
p *= i
for i in args:
mu *= i
return mu / p
#上边的有点绕了,再简化
def solution(*args) -> int:
if len(args) == 0:
return -1
new_list = []
for i, i_value in enumerate(args):
for j_value in args[i + 1:]:
tmp = i_value
while tmp != j_value:
if tmp > j_value:
tmp = tmp - j_value
else:
j_value = j_value -tmp
new_list.append(j_value)
mu, p = 1, 1
for i in new_list:
p *= i
for i in args:
mu *= i
return mu / p
assert solution(2, 3, 4) == 12
assert solution(2, 5) == 10
assert solution(9) == 9
assert solution(3) == 3
assert solution() == -1
def solution(*args):
mul, mul_param = 1, 1
args = sorted(args)
for j, v in enumerate(args):
mul *= v
for m in args[j + 1:]:
n = v
while True:
r = m % n
if r == 0:
mul_param *= n
break
else:
m = n
n = r
return mul / mul_param
assert solution(2, 3, 4) == 12
assert solution(2, 5) == 10
assert solution(9) == 9
assert solution(3) == 3
def solution(*args)-> int:
# your code here
ls = [i for i in args]
if 0 in args:
return 0
elif ls == 0:
return 1
elif len(ls) == 1:
return ls[0]
elif len(ls) == 2:
return ls[0]*ls[1]
else:
num = max(ls)
a = 0
while True:
a+=1
count_num = a*num
l = 0
for i in ls:
if count_num % i ==0:
l+=1
if l ==len(ls):
return count_num
if __name__ == '__main__':
assert solution(2,3,4) == 12
assert solution(2,5) == 10
assert solution(9) == 9
assert solution(2, 4, 27, 8, 3, 9, 24, 216, 288, 51288) == 1846368
def solution(*args):
# your code here
# 转换为可变列表
l = [i for i in args]
# 输入为空数据,则返回None
if l == []:
return None
# 输入一个正整数,则直接返回该数据本身
if len(l) == 1:
return l[0]
# 输入正整数数量大于等于2时,每次取出来两个取最小公倍数,并把取出来的数据从列表删除,同时把取出来两个数的最小公倍数输入列表中
while len(l) >= 2:
n, m = l[0], l[1]
l.pop(0), l.pop(0)
s = []
tmp = 1
j = 2
while True:
if n % j == 0 and m % j == 0:
s.append(j)
n, m = n // j, m // j
continue
if j > n or j > m:
break
j += 1
for k in s:
tmp *= k
tmp *= n*m
l.append(tmp)
return l[0]
def solution(*args) -> int:
res = 1
while res >= 0:
l = 0
for i in args:
if res % int(i) != 0:
break
else:
l += 1
if l == len(args):
break
res += 1
return res
assert solution(2, 3, 4) == 12
assert solution(2, 5) == 10
assert solution(9) == 9
assert solution(2, 4, 27, 8, 3, 9, 24, 216, 288, 51288) == 1846368