結果

問題 No.316 もっと刺激的なFizzBuzzをください
ユーザー ともきともき
提出日時 2016-03-26 01:30:31
言語 Rust
(1.72.1)
結果
AC  
実行時間 1 ms / 1,000 ms
コード長 1,342 bytes
コンパイル時間 1,722 ms
コンパイル使用メモリ 141,924 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-13 16:17:50
合計ジャッジ時間 2,114 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 0 ms
4,384 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,384 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,384 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 0 ms
4,380 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 1 ms
4,376 KB
testcase_35 AC 1 ms
4,380 KB
testcase_36 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused import: `std::fmt`
 --> Main.rs:3:5
  |
3 | use std::fmt;
  |     ^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

warning: 1 warning emitted

ソースコード

diff #

use std::io;
use std::str::FromStr;
use std::fmt;

fn read_line() -> String {
    let mut ret = String::new();
    io::stdin().read_line(&mut ret).expect("read_line failed");
    ret.trim().to_string()
}

fn read_one<F>() -> F where F: FromStr {
    // FromStr has type Error in its struct.
    // https://doc.rust-lang.org/std/str/trait.FromStr.html
    // String#parse return Result<F, F::Err>,
    // and unwrap is only available in Result<T, Result>
    match read_line().parse::<F>() {
        Ok(v)  => v,
        Err(_) => panic!("failed to parse.")
    }
}

fn read_many<F>() -> Vec<F> where F: FromStr {
    read_line().split(' ').map(
        |s| match s.parse::<F>() {
            Ok(v)  => v,
            Err(_) => panic!("failed to parse.")
        }
    ).collect()
}
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------

fn gcd(x: i64, y: i64) -> i64 {
    if y == 0 {
        x
    } else {
        gcd(y, x%y)
    }
}
fn lcm(x: i64, y: i64) -> i64 {
    x * y / gcd(x, y)
}

fn main() {
    let n: i64      = read_one();
    let v: Vec<i64> = read_many();
    let (a, b, c) = (v[0], v[1], v[2]);

     let ans = (n/a)+(n/b)+(n/c)-(n/lcm(a,b))-(n/lcm(b,c))-(n/lcm(c,a))+(n/lcm(lcm(a,b),c));
    println!("{}", ans)
}
0