Skip to content

Instantly share code, notes, and snippets.

@whatalnk
Created September 21, 2017 09:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whatalnk/55c015f6b6cde87e7b4f82cde7c3633b to your computer and use it in GitHub Desktop.
Save whatalnk/55c015f6b6cde87e7b4f82cde7c3633b to your computer and use it in GitHub Desktop.
AtCoder ABC #070 C
use std::io;
fn gets() -> String {
let mut buf = String::new();
io::stdin().read_line(&mut buf).ok();
return buf
}
fn gcd(a: i64, b: i64) -> i64 {
if b == 0 {
return a;
}
return gcd(b, a % b);
}
fn lcm(a: i64, b: i64) -> i64 {
let g = gcd(a, b);
return a / g * b;
}
fn main() {
let line = gets();
let n = line.trim().parse::<usize>().unwrap();
let mut ans = 1;
for _ in 0..n {
let line = gets();
let t = line.trim().parse::<i64>().unwrap();
ans = lcm(ans, t);
}
println!("{}", ans);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment