namespace Solutions;
public static class Util
{
///
/// Naive least common multiple implementation.
///
///
///
///
public static long Lcm(long a, long b) => a * b / Gcd(a, b);
///
/// Naive greatest common denominator implementation.
///
///
///
///
public static long Gcd(long a, long b)
{
while (true)
{
if (b == 0) return a;
var a1 = a;
a = b;
b = a1 % b;
}
}
///
/// Quickly parse an integer from a ReadOnlySpan by ascii index and radix shifting.
///
///
///
public static int ParseIntFast(ReadOnlySpan span)
{
var result = 0;
for (var i = 0; i < span.Length; i++)
result = result * 10 + span[i] - '0';
return result;
}
///
/// Quickly parse a long from a ReadOnlySpan by ascii index and radix shifting.
///
///
///
public static long ParseLongFast(ReadOnlySpan span)
{
var result = 0L;
for (var i = 0; i < span.Length; i++)
result = result * 10 + span[i] - '0';
return result;
}
}