結果

問題 No.316 もっと刺激的なFizzBuzzをください
ユーザー yukyuyukyu
提出日時 2021-02-28 15:06:02
言語 Rust
(1.77.0)
結果
AC  
実行時間 1 ms / 1,000 ms
コード長 1,349 bytes
コンパイル時間 936 ms
コンパイル使用メモリ 159,232 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-10 15:59:03
合計ジャッジ時間 1,836 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 0 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 0 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 0 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 0 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 1 ms
5,376 KB
testcase_21 AC 0 ms
5,376 KB
testcase_22 AC 1 ms
5,376 KB
testcase_23 AC 0 ms
5,376 KB
testcase_24 AC 1 ms
5,376 KB
testcase_25 AC 1 ms
5,376 KB
testcase_26 AC 1 ms
5,376 KB
testcase_27 AC 1 ms
5,376 KB
testcase_28 AC 1 ms
5,376 KB
testcase_29 AC 1 ms
5,376 KB
testcase_30 AC 1 ms
5,376 KB
testcase_31 AC 1 ms
5,376 KB
testcase_32 AC 0 ms
5,376 KB
testcase_33 AC 1 ms
5,376 KB
testcase_34 AC 1 ms
5,376 KB
testcase_35 AC 1 ms
5,376 KB
testcase_36 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::*;
use std::str::FromStr;

fn main() {
    let a: String = read();
    let n = a.parse::<i64>().unwrap();
    let inputs = (0..3).map(|_| read()).collect::<Vec<i64>>();
    exec(n, inputs);
}

fn exec(n: i64, inputs: Vec<i64>) {
    let count = (n / inputs[0]) + (n / inputs[1]) + (n / inputs[2]);
    let exclude = (n / get_lcm(inputs[0], inputs[1]))
        + (n / get_lcm(inputs[0], inputs[2]))
        + (n / get_lcm(inputs[1], inputs[2]));
    let include_triple = n / get_lcm(get_lcm(inputs[0], inputs[1]), inputs[2]);
    println!("{}", count - exclude + include_triple);
}

fn get_lcm(a: i64, b: i64) -> i64 {
    if a == b {
        return a;
    } else {
        let gcd = match a > b {
            true => rec_gcd(a, b),
            _ => rec_gcd(b, a),
        };
        return (a * b) / gcd;
    }
}

fn rec_gcd(a: i64, b: i64) -> i64 {
    let mod_number = a % b;
    if mod_number == 0 {
        return b;
    } else {
        return rec_gcd(b, mod_number);
    }
}


fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}
0