結果
問題 | No.316 もっと刺激的なFizzBuzzをください |
ユーザー |
![]() |
提出日時 | 2018-11-20 22:49:10 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 1 ms / 1,000 ms |
コード長 | 850 bytes |
コンパイル時間 | 14,389 ms |
コンパイル使用メモリ | 378,432 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-24 15:50:31 |
合計ジャッジ時間 | 15,794 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 33 |
ソースコード
use std::io::Read; use std::mem; fn gcd(mut x: usize, mut y: usize) -> usize { while x != 0 { y %= x; mem::swap(&mut x, &mut y); } y } fn lcm(x: usize, y: usize) -> usize { let xy_gcd = gcd(x, y); x * y / xy_gcd } fn main() { let mut buf = String::new(); std::io::stdin().read_to_string(&mut buf).unwrap(); let mut iter = buf.split_whitespace(); let n: usize = iter.next().unwrap().parse().unwrap(); let a: usize = iter.next().unwrap().parse().unwrap(); let b: usize = iter.next().unwrap().parse().unwrap(); let c: usize = iter.next().unwrap().parse().unwrap(); let ab_lcm = lcm(a, b); let ac_lcm = lcm(a, c); let bc_lcm = lcm(b, c); let abc_lcm = lcm(a, bc_lcm); println!("{}", n/a + n/b + n/c - n/ab_lcm - n/ac_lcm - n/bc_lcm + n/abc_lcm); }