Files
github/noc.sh
2026-02-28 11:42:38 +03:00

33 lines
680 B
Bash
Raw 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
if ! command -v gcd &> /dev/null; then
source ./nod.sh
fi
lcm() {
local a=$1
local b=$2
if [ $a -eq 0 ] || [ $b -eq 0 ]; then
echo 0
return 0
fi
local gcd_val=$(gcd $a $b)
local lcm_val=$((a * b / gcd_val))
echo $lcm_val
}
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
if [ $# -ne 2 ]; then
exit 1
fi
if ! [[ "$1" =~ ^[0-9]+$ ]] || ! [[ "$2" =~ ^[0-9]+$ ]]; then
echo "Ошибка: Аргументы должны быть целыми положительными числами"
exit 1
fi
result=$(lcm $1 $2)
echo "НОК($1, $2) = $result"
fi