結果

問題 No.593 4進FizzBuzz
ユーザー nebukuro09
提出日時 2017-11-10 22:37:32
言語 D
(dmd 2.109.1)
結果
AC  
実行時間 26 ms / 2,000 ms
コード長 745 bytes
コンパイル時間 838 ms
コンパイル使用メモリ 111,612 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-06-12 22:24:47
合計ジャッジ時間 3,150 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop;


void main() {
    auto S = readln.chomp;
    auto N = S.length.to!int;

    int three = 0;
    int five = 0;
    int p3 = 1;
    int p5 = 1;

    foreach (i; iota(N-1, -1, -1)) {
        int x3 = (S[i] - '0') * p3;
        (three += x3 % 3) %= 3;
        p3 = p3 * 4 % 3;

        int x5 = (S[i] - '0') * p5;
        (five += x5 % 5) %= 5;
        p5 = p5 * 4 % 5;
    }

    if (three == 0 && five == 0)
        writeln("FizzBuzz");
    else if (three == 0)
        writeln("Fizz");
    else if (five == 0)
        writeln("Buzz");
    else
        writeln(S);
}
0