Connection Status:
Competition Arena > FizzBuzzTurbo
TCO14 Round 1C · 2014-03-26 · by misof · Simple Math, Simple Search, Iteration
Class Name: FizzBuzzTurbo
Return Type: long[]
Method Name: counts
Arg Types: (long long, long long)
Problem Statement

Problem Statement

Fizz Buzz is a simple game used to teach kids about divisibility. The goal of the game is to say positive integers in increasing order, with a twist: You don't say the numbers divisible by 3 and 5. Instead, whenever a number was divisible by 3 you say "fizz" and for a number divisible by 5 you say "buzz". (Thus, if a number was divisible by 15, you say "fizzbuzz".)

Here is how the game starts: 1, 2, fizz, 4, buzz, fizz, 7, 8, fizz, buzz, 11, fizz, 13, 14, fizzbuzz, 16, 17, fizz, 19, buzz, fizz, 22, 23, fizz, buzz, 26, fizz, 28, 29, fizzbuzz, 31, 32, fizz, 34, buzz, fizz, ...

Fizz Buzz has also become a traditional programming interview question. However, in this problem we have a more tricky assignment for you.

You are given longs A and B. Consider the part of the game that corresponds to integers from A to B, inclusive. During this part of the game, you will say "fizz" X times, "buzz" Y times, and "fizzbuzz" Z times. Return a long[] with three elements: {X,Y,Z}.

Notes

  • The return value can be quite large. Make sure to use the appropriate data type.

Constraints

  • A will be between 1 and 10^18, inclusive.
  • B will be between A and 10^18, inclusive.
Examples
0)
1
4
Returns: {1, 0, 0 }

This is the sequence "1, 2, fizz, 4".

1)
2
6
Returns: {2, 1, 0 }

This is the sequence "2, fizz, 4, buzz, fizz".

2)
150
165
Returns: {4, 2, 2 }

This sequence begins and ends with a "fizzbuzz". There are some "fizz"es and some "buzz"es inbetween.

3)
474747
747474
Returns: {72728, 36363, 18182 }
4)
1
1
Returns: {0, 0, 0 }

Submissions are judged against all 137 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class FizzBuzzTurbo with a public method vector<long long> counts(long long A, long long B) · 137 test cases · 2 s / 256 MB per case

Submitting as anonymous