結果

問題 No.593 4進FizzBuzz
ユーザー nebukuro09nebukuro09
提出日時 2017-11-10 22:30:25
言語 D
(dmd 2.109.1)
結果
WA  
実行時間 -
コード長 749 bytes
コンパイル時間 793 ms
コンパイル使用メモリ 109,708 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-12 22:24:05
合計ジャッジ時間 4,044 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3 WA * 1
other AC * 23 WA * 8
権限があれば一括ダウンロードができます

ソースコード

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("FizzBuzz");
    else
        writeln(S);
}
0