Logo

Programming-Idioms

History of Idiom 74 > diff from v47 to v48

Edit summary for version 48 by programming-idioms.org:
[Rust] Fix DemoURL

Version 47

2021-03-31, 20:44:27

Version 48

2021-03-31, 20:46:00

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
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/?version=stable&mode=debug&edition=2015&gist=77c462bfed2ce099152b768de15be928