Добавил НОК
This commit is contained in:
25
script_LCM.sh
Executable file
25
script_LCM.sh
Executable file
@@ -0,0 +1,25 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
if [ $# -ne 2 ]; then
|
||||||
|
echo "Использование: $0 <число1> <число2>"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
a=$1
|
||||||
|
b=$2
|
||||||
|
|
||||||
|
gcd() {
|
||||||
|
local x=$1
|
||||||
|
local y=$2
|
||||||
|
while [ $y -ne 0 ]; do
|
||||||
|
local t=$((x % y))
|
||||||
|
x=$y
|
||||||
|
y=$t
|
||||||
|
done
|
||||||
|
echo $x
|
||||||
|
}
|
||||||
|
|
||||||
|
gcd_val=$(gcd $a $b)
|
||||||
|
lcm=$(( (a * b) / gcd_val ))
|
||||||
|
|
||||||
|
echo $lcm
|
||||||
Reference in New Issue
Block a user