Replace usage of fractions.gcd with a conditional that uses math.gcd if
it is available and which falls back to fractions.gcd if it is not. This
allows the code to work in Python 3.9+ where the deprecated
fractions.gcd function was removed.
If support for versions of Python older than 3.5 is dropped then this
code could be simplified to just use math.gcd.
Replace usage of fractions.gcd with a conditional that uses math.gcd if it is available and which falls back to fractions.gcd if it is not. This allows the code to work in Python 3.9+ where the deprecated fractions.gcd function was removed.
If support for versions of Python older than 3.5 is dropped then this code could be simplified to just use math.gcd.