Logo

Programming-Idioms

History of Idiom 75 > diff from v6 to v7

Edit summary for version 7 by :

Version 6

2015-08-22, 10:25:14

Version 7

2015-08-22, 15:45:31

Idiom #75 Compute LCM

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

Idiom #75 Compute LCM

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

Imports
extern crate num;

use num::Integer;
use num::bigint::BigInt;
Code
let x = a.lcm(&b);
Comments bubble
Part of the num crate's `Integer` trait.
Doc URL
http://doc.rust-lang.org/num/num/integer/trait.Integer.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%20%20%20%20let%20b%20%3D%20BigInt%3A%3Aparse_bytes(b%229000000000000%22%2C%2010).unwrap()%3B%0A%20%20%20%20let%20x%20%3D%20a.lcm(%26b)%3B%0A%20%20%20%20println!(%22%7B%7D%22%2C%20x)%3B%0A%7D%0A&version=stable