fork download
  1. /*
  2.  * Description : Greatest Common Divisor( Euclid'algorithm ) in Rust languange.
  3.  * Author : Adrian Statescu <mergesortv@gmail.com>.
  4.  * License : MIT.
  5.  */
  6.  
  7. fn gcd(mut x: u64, mut y: u64) -> u64 {
  8.  
  9. assert!(x != 0 && y != 0);
  10.  
  11. while y != 0 {
  12.  
  13. let t = x % y;
  14. x = y;
  15. y = t;
  16. }
  17. x
  18. }
  19.  
  20. fn get_input() -> String {
  21.  
  22. let mut buffer = String::new();
  23.  
  24. std::io::stdin().read_line(&mut buffer).expect("Failed");
  25.  
  26. buffer
  27. }
  28.  
  29. fn main() {
  30.  
  31. let x = get_input().trim().parse::<u64>().unwrap();
  32. let y = get_input().trim().parse::<u64>().unwrap();
  33.  
  34. println!("Euclid ({:?}, {:?}) -> {:?}", x, y, gcd(x,y));
  35. }
Success #stdin #stdout 0s 4180KB
stdin
7919
9
stdout
Euclid (7919, 9) -> 1