結果

問題 No.294 SuperFizzBuzz
コンテスト
ユーザー koba-e964
提出日時 2025-12-16 09:55:32
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 80 ms / 5,000 ms
コード長 994 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 11,715 ms
コンパイル使用メモリ 402,460 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2025-12-16 09:55:45
合計ジャッジ時間 12,732 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 12
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

use std::io::{self, Read};

fn calc(mut t: u64, mut l: u32, mut rem: i32) -> (u64, u32) {
    loop {
        if (t >> l) != 0 {
            // move to next length
            t = 1;
            l += 1;
            continue;
        }
        if (t.count_ones() % 3) != 0 {
            // keep length, fix popcount%3
            t += 2;
            continue;
        }
        if rem == 0 {
            return (t, l);
        }
        // accept this t as one result, move to next candidate
        t += 2;
        rem -= 1;
    }
}

fn main() {
    // Read all input
    let mut s = String::new();
    io::stdin().read_to_string(&mut s).unwrap();
    let n: i32 = s.trim().parse().unwrap();

    let (res, len) = calc(1, 1, n - 1);

    let mut out = String::with_capacity(len as usize);
    for i in 0..len {
        let bit = 1u64 << (len - i - 1);
        if (res & bit) != 0 {
            out.push('5');
        } else {
            out.push('3');
        }
    }

    println!("{out}");
}
0