Skip to content

Instantly share code, notes, and snippets.

@RIGIK93
Last active June 11, 2023 01:24
Show Gist options
  • Save RIGIK93/ecb96d61af2eb809e15f80f7aeec2f4e to your computer and use it in GitHub Desktop.
Save RIGIK93/ecb96d61af2eb809e15f80f7aeec2f4e to your computer and use it in GitHub Desktop.
Euclidean algorithm for computing greatest common divisor in rust
use num::traits::{Zero, Rem};
fn gcd<T>(a: T, b: T) -> T
where
T: Zero + Rem<Output = T> + std::cmp::PartialEq + Copy,
{
if b == T::zero() {
return a;
}
gcd(b, a % b)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment