結果

問題 No.593 4進FizzBuzz
ユーザー hatoohatoo
提出日時 2017-11-10 22:40:31
言語 Rust
(1.72.1)
結果
AC  
実行時間 32 ms / 2,000 ms
コード長 2,599 bytes
コンパイル時間 5,999 ms
コンパイル使用メモリ 137,908 KB
実行使用メモリ 19,568 KB
最終ジャッジ日時 2023-08-16 03:21:24
合計ジャッジ時間 7,682 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,328 KB
testcase_02 AC 1 ms
4,328 KB
testcase_03 AC 1 ms
4,332 KB
testcase_04 AC 1 ms
4,328 KB
testcase_05 AC 1 ms
4,332 KB
testcase_06 AC 1 ms
4,328 KB
testcase_07 AC 1 ms
4,332 KB
testcase_08 AC 1 ms
4,332 KB
testcase_09 AC 1 ms
4,332 KB
testcase_10 AC 1 ms
4,328 KB
testcase_11 AC 1 ms
4,328 KB
testcase_12 AC 1 ms
4,336 KB
testcase_13 AC 1 ms
4,332 KB
testcase_14 AC 1 ms
4,328 KB
testcase_15 AC 0 ms
4,332 KB
testcase_16 AC 29 ms
19,472 KB
testcase_17 AC 28 ms
19,512 KB
testcase_18 AC 27 ms
19,568 KB
testcase_19 AC 28 ms
19,540 KB
testcase_20 AC 23 ms
19,552 KB
testcase_21 AC 31 ms
19,472 KB
testcase_22 AC 32 ms
19,552 KB
testcase_23 AC 24 ms
19,540 KB
testcase_24 AC 27 ms
19,540 KB
testcase_25 AC 28 ms
19,560 KB
testcase_26 AC 31 ms
19,548 KB
testcase_27 AC 28 ms
19,552 KB
testcase_28 AC 23 ms
19,548 KB
testcase_29 AC 28 ms
19,524 KB
testcase_30 AC 22 ms
19,536 KB
testcase_31 AC 26 ms
19,468 KB
testcase_32 AC 28 ms
19,544 KB
testcase_33 AC 28 ms
19,480 KB
testcase_34 AC 27 ms
19,532 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet, BinaryHeap};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[allow(unused_imports)]
use std::io::stdin;

mod util {
    use std::io::stdin;
    use std::str::FromStr;
    use std::fmt::Debug;

    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
}

#[allow(unused_macros)]
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    get!($t)
                   ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    get!($($t),*)
                   ).collect::<Vec<_>>()
    };
    ($t:ty ;;) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn f(n: &[usize], m: usize) -> bool {
    let mut d = 1;
    let mut sum = 0;

    for &x in n {
        sum += d * x % m;
        sum %= m;
        d = d * 4 % m;
    }

    sum == 0
}

fn main() {
    let s = util::line();
    let n: Vec<usize> = s.chars()
        .rev()
        .map(|c| (c as u8 - '0' as u8) as usize)
        .collect();

    if f(&n, 3) && f(&n, 5) {
        println!("FizzBuzz");
    } else if f(&n, 3) {
        println!("Fizz");
    } else if f(&n, 5) {
        println!("Buzz");
    } else {
        println!("{}", s);
    }
}
0