Skip to content

Instantly share code, notes, and snippets.

@tnoda
Last active Aug 29, 2015
Embed
What would you like to do?
The FizzBuzz Question in the Imedio

The FizzBuzz Question in the Imedio

Imedians who originate from the planet Imedio love games of the Earth. The FizzBuzz Question is one of the most popular game among them, and is the winner of Imedian Game of the Year 2014.

Its rule is defined in a Wikipedia article as follows:

Fizz buzz is a group word game for children to teach them about division. Players take turns to count incrementally, replacing any number divisible by three with the word “fizz”, and any number divisible by five with the word “buzz”.

[…]

The player designated to go first says the number “1”, and each player thenceforth counts one number in turn. However, any number divisible by three is replaced by the word fizz and any divisible by five by the word buzz. Numbers divisible by both become fizz buzz.

For example, a typical round of fizz buzz would start as follows:

1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, Fizz Buzz,
16, 17, Fizz, 19, Buzz, Fizz, 22, 23, Fizz, Buzz, 26, Fizz, 28, 29, Fizz Buzz,
 31, 32, Fizz, 34, Buzz, Fizz, ...

$N$ Imedians are forming a line from west to east, and the westernmost Imedian has just started a FizzBuzz game. Find the number or words that the last easternmost Imedian will say.

Input: standard input

The only line of the input contains a number \[ N (0 < N < 101000000) \].

Output: standard output

If the last Imedian count a number, print the resulting number in a single line. Otherwise, print either “Fizz”, “Buzz”, or “Fizz Buzz” (without quotes, case-sensitive) appropriately in a single line.

Time limit per test

5 seconds

<<sample>>Sample tests

Case 1

Input

3

Output

Fizz

Case 2

Input

5

Output

Buzz

Case 3

Input

7

Output

7

Case 4

Input

15

Output

Fizz Buzz

Case 5

Input

1999999999999999995

Output

Fizz Buzz

イメディオ星の FizzBuzz

イメディオ星のイメディオ星人は地球のゲームが大好き。中でも FizzBuzz は最も人気のあるゲームで、2014 年のイメディオゲーム大賞を受賞したほどです。

FizzBuzz のルールは Wikipedia の記事 で次のように定義されています。

最初のプレイヤーは「1」と数字を発言する。次のプレイヤーは直前のプレイヤーの次の数字を発言していく。ただし、3で割り切れる場合は 「Fizz」、5で割り切れる場合は 「Buzz」、両者で割り切れる場合は 「Fizz Buzz」を数の代わりに発言しなければならない。

ゲームは、次のように進行します

1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, Fizz Buzz,
16, 17, Fizz, 19, Buzz, Fizz, 22, 23, Fizz, Buzz, 26, Fizz, 28, 29, Fizz Buzz,
31, 32, Fizz, 34, Buzz, Fizz, ...

$N$ 人のイメディオ星人が西から東に向かって一列に並んでいます。今、最西端のイメディオ星人から FizzBuzz が始まりました。最東端にいる最後のイメディオ星人が何と言うかを答えてください。

入力(標準入力から読み込むものとします)

$1$ 以上 $101000000$ 未満の整数 $N$ が一行で与えられます。

出力(標準出力に書き出すものとします)

答えを 1 行で出力してください。

制限時間

1 実行あたり 5 秒

英語版の Sample tests を参考にしてください。

This file has been truncated, but you can view the full file.
View raw

(Sorry about that, but we can’t show files that are this big right now.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment