private static bool TryGetGcd(long a, long b, out long result)
{
result = 0;
var c = System.Numerics.BigInteger.GreatestCommonDivisor(a, b);
if (c <= long.MaxValue && c >= long.MinValue)
{
result = (long)c;
return true;
}
return false; // would overflow
}