From 0823e9e7a733bb3216043110c9d7f2b598dd5a29 Mon Sep 17 00:00:00 2001 From: Ad0n Date: Sat, 14 Feb 2026 19:51:09 +0300 Subject: [PATCH] LCM script by Aleksandr --- script_LCM.sh | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 script_LCM.sh diff --git a/script_LCM.sh b/script_LCM.sh new file mode 100644 index 0000000..f2eddae --- /dev/null +++ b/script_LCM.sh @@ -0,0 +1,28 @@ + GNU nano 7.2 script_LCM.sh +#!/bin/bash + +if [ $# -ne 2 ]; then + echo "Использование: $0 <число1> <число2>" + exit 1 +fi + +gcd() { + local a=$1 + local b=$2 + while [ $b -ne 0 ]; do + local temp=$b + b=$((a % b)) + a=$temp + done + echo $a +} + +lcm() { + local a=$1 + local b=$2 + local gcd_val=$(gcd $a $b) + echo $((a * b / gcd_val)) +} + +result=$(lcm $1 $2) +echo $result