#euclidean #extended #lib #finding #congruence #multiple #euc

euc_lib

Easy to use implementation of extended and normanl Euclidean algorithm

14 unstable releases (3 breaking)

0.4.0 Jun 17, 2023
0.3.2 Apr 24, 2023
0.2.6 Feb 21, 2023
0.2.3 Jan 29, 2023
0.1.9 Jan 25, 2023

#634 in Algorithms

Download history 44/week @ 2024-02-23 9/week @ 2024-03-01 1/week @ 2024-03-08

54 downloads per month

GPL-3.0 license

16KB
165 lines

euc_lib

Liblary implements:

  • euc - euclidean algorithm
  • euc_ext - extended euclidean algorithm
  • lcm - least common multiple
  • congruence - congruence soliving function, finding smallest x for solution

Want to contribute?:

My github:

github

Project:

github

Support:

https://www.buymeacoffee.com/WhiskyAKM



Example usage:

Euclides

Extended

Program

use euc_lib;
fn main() {
    prinln!("{}", euc_lib::I32::euc_ext(135, 35));
}

Output

NWD = 5, S = -1, T = 4

Simple

Program

use euc_lib;
fn main() {
    prinln!("{}", euc_lib::I32::euc(135, 35)); // there is recursive variant too: euc_recursive(135,35)
}

Output

5

Vector as an argument

Program

use euc_lib;
fn main() {
    println!("{:?}", euc_lib::I32::euc_from_vec(vec![21, 14, 56]));
}

Output

Ok(7)

LCM

Simple

This version implements Least common multiple calculating method using gcd (Euclidean algorithm)

Program

use euc_lib;
fn main () {
    println!("{}", euc_lib::I32::lcm(21, 6)) // there is recursive variant too: lcm_recursive
}

Output

42

Vector as argument

Program

use euc_lib;
fn main() {
    println!("{:?}", euc_lib::I32::lcm_from_vec(vec![12,4,8]))
}

Output

Ok(24)

Congruence

Program

use euc_lib;
fn main() {
    println!("{:?}", euc_lib::I32::congruence(9,21,30))
}

Output

Ok(9)

i64 support

To use i64 versions of all functions just use euc_lib::I64 instead of euc_lib::I32

Example of I64 usage

Program

use euc_lib;
fn main() {
    prinln!("{}", euc_lib::I64::euc_ext(135, 35));
}

Output

NWD = 5, S = -1, T = 4

Dependencies

~470KB