Logo

Programming-Idioms

History of Idiom 74 > diff from v46 to v47

Edit summary for version 47 by programming-idioms.org:
[Rust] +DocURL

Version 46

2020-12-24, 20:20:52

Version 47

2021-03-31, 20:44:27

Idiom #74 Compute GCD

Compute the greatest common divisor x of big integers a and b. Use an integer type able to handle huge numbers.

Idiom #74 Compute GCD

Compute the greatest common divisor x of big integers a and b. Use an integer type able to handle huge numbers.

Variables
x,a,b
Variables
x,a,b
Imports
extern crate num;

use num::Integer;
use num::bigint::BigInt;
Imports
extern crate num;

use num::Integer;
use num::bigint::BigInt;
Code
let x = a.gcd(&b);
Code
let x = a.gcd(&b);
Comments bubble
Uses the num crate's `Integer` trait.
Comments bubble
Uses the num crate's `Integer` trait.
Doc URL
https://docs.rs/num/0.4.0/num/integer/fn.gcd.html
Demo URL
https://play.rust-lang.org/?code=extern%20crate%20num%3B%0A%0Ause%20num%3A%3AInteger%3B%0Ause%20num%3A%3Abigint%3A%3ABigInt%3B%0A%0Afn%20main()%20%7B%0A%20%20%20%20let%20a%20%3D%20BigInt%3A%3Aparse_bytes(b%226000000000000%22%2C%2010).unwrap()%3B%0A%2
Demo URL
https://play.rust-lang.org/?code=extern%20crate%20num%3B%0A%0Ause%20num%3A%3AInteger%3B%0Ause%20num%3A%3Abigint%3A%3ABigInt%3B%0A%0Afn%20main()%20%7B%0A%20%20%20%20let%20a%20%3D%20BigInt%3A%3Aparse_bytes(b%226000000000000%22%2C%2010).unwrap()%3B%0A%2