2 Commits

Author SHA1 Message Date
0cd515b428 Обновить script_LCM.sh 2026-04-20 10:22:26 +03:00
Максим Тер-Томасов
bfd0168b25 Add LCM script (Task 2) 2026-04-19 14:34:14 +03:00

17
script_LCM.sh Executable file
View File

@@ -0,0 +1,17 @@
#!/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)"