We can compute the Greatest Common Divisor (GCD) using Iterative Divide/Remainder Method. The following is the GCD implementation in BASH Programming:
#!/bin/bash
function gcd() {
local x=$1
local y=$2
while [ $y -gt 0 ]; do
local t=$x
x=$y
y=$((t%y))
done
echo $x
}
And the Least Common Multiples can be computed as the multipication of two integers divided by their GCD:
#!/bin/bash
function lcm() {
local x=$1
local y=$2
local g=$(gcd $x $y)
echo $((x*y/g))
}
See also: Smallest Multiple Algorithm using Bruteforce or GCD/LCM
The GCD Program in BASH: BASH Function to Compute the Greatest Common Divisor and Least Common Multiples
--EOF (The Ultimate Computing & Technology Blog) --
Reposted to Blog
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Thank you for reading ^^^^^^^^^^^^^^^
NEW! Following my Trail (Upvote or/and Downvote)
Follow me for topics of Algorithms, Blockchain and Cloud.
I am @justyy - a Steem Witness
https://steemyy.com
My contributions
- Video Downloader
- Steem Blockchain Tools
- Free Cryptos API
- VPS Database
- Computing Technology Blog
- A few useless tools
- And some other online software/tools
- Merge Files/Videos
- LOGO Turtle Programming Chrome Extension
- Teaching Kids Programming - Youtube Channel and All Contents
Delegation Service
Important Update of Delegation Service!
Support me
If you like my work, please:
- Buy Me a Coffee, Thanks!
- Become my Sponsor, Thanks!
- Voting for me:
https://steemit.com/~witnesses type in justyy and click VOTE
- Delegate SP: https://steemyy.com/sp-delegate-form/?delegatee=justyy
- Vote @justyy as Witness: https://steemyy.com/witness-voting/?witness=justyy&action=approve
- Set @justyy as Proxy: https://steemyy.com/witness-voting/?witness=justyy&action=proxy
Alternatively, you can vote witness or set proxy here: https://steemit.com/~witnesses
Dear @justyy sir,
I missed the daily upvote for the last post :
https://steemit.com/hive-119845/@besticofinder/rose-from-my-mom-s-garden
please kindly check.
Thank you
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
voted. here.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Thank you
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
hello, sir @justyy, today again I missed upvote from your trail. I'm an active delegator(66K SP) & voted you as witness. please, check the following post --
https://steemit.com/hive-129948/@rme/announcement-of-official-charity-account-of-amar-bangla-blog
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
voted here: https://steemit.com/dtube/@rme/qww5m3#@rme/qww5m3
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit