Skip to content

Instantly share code, notes, and snippets.

@takakabe
Last active May 31, 2022 15:19
Show Gist options
  • Save takakabe/5805325620ad5f0b005cfd117fc0396a to your computer and use it in GitHub Desktop.
Save takakabe/5805325620ad5f0b005cfd117fc0396a to your computer and use it in GitHub Desktop.
import sys
import math
args = sys.argv
value1 = int(args[1])
value2 = int(args[2])
i = 2
divisor_list = []
while i < value1 or i < value2:
if value1 % i == 0 and value2 % i == 0:
value1 = value1 // i
value2 = value2 // i
divisor_list.append(i)
i += 1
gcd = math.prod(divisor_list)
print(gcd)
import sys
import math
args = sys.argv
value1 = int(args[1])
value2 = int(args[2])
i = 2
divisor_list = []
while i < value1 or i < value2:
if value1 % i == 0 and value2 % i == 0:
value1 = value1 // i
value2 = value2 // i
divisor_list.append(i)
i += 1
divisor_list.append(value1)
divisor_list.append(value2)
lcm = math.prod(divisor_list)
print(lcm)
@takakabe
Copy link
Author

takakabe commented May 31, 2022

vagrant@ubuntu-jammy:~/math/src$ docker run -it --rm --name gcm -v "$PWD/src":/src -w /src python:3 python gcd.py 60 75
15
vagrant@ubuntu-jammy:~/math/src$ docker run -it --rm --name gcm -v "$PWD/src":/src -w /src python:3 python lcm.py 30 42
210

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment