Обновить script_LCM.sh

This commit is contained in:
2026-04-20 10:22:26 +03:00
parent bfd0168b25
commit 0cd515b428

View File

@@ -14,20 +14,4 @@ lcm() {
if [ $# -ne 2 ]; then if [ $# -ne 2 ]; then
echo "Usage: $0 <num1> <num2>"; exit 1 echo "Usage: $0 <num1> <num2>"; exit 1
fi fi
echo "НОК($1, $2) = $(lcm $1 $2)"#!/bin/bash
gcd() {
local a=$1 b=$2
while [ $b -ne 0 ]; do
local temp=$b; b=$((a % b)); a=$temp
done
echo $a
}
lcm() {
local a=$1 b=$2
local g=$(gcd $a $b)
echo $(( (a * b) / g ))
}
if [ $# -ne 2 ]; then
echo "Usage: $0 <num1> <num2>"; exit 1
fi
echo "НОК($1, $2) = $(lcm $1 $2)" echo "НОК($1, $2) = $(lcm $1 $2)"