Files
lab_git/script_LCM.sh
Максим Тер-Томасов bfd0168b25 Add LCM script (Task 2)
2026-04-19 14:34:14 +03:00

34 lines
645 B
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/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)"#!/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)"