Fizz Coke

View as PDF

Submit solution

Points: 7 (partial)
Time limit: 1.0s
Java 1.2s
Memory limit: 64M
PyPy 2 128M
PyPy 3 128M

Author:
Problem type

As a new CS graduate, your friend has memorized the Fizz Buzz problem and has his first interview today. Unfortunately for him, the interviewer thought that Fizz Buzz was too easy. He has proposed a new version, as shown:

You are given a number M, the number of numbers you should check divisibility by, and N, the number you should go up to.

The next M lines will contain a number di, and its associated word wi.

Counting from 1 to N, print the associated word(s) wi in increasing order of di if the current number is divisible by any of the numbers di; otherwise, print the current number.

Your friend is panicking because he only memorized the 3 and 5 version. He is now sitting in the washroom, asking you for help. Can you help him?

Constraints

1diN

It is guaranteed that all di will be unique.

All words wi are between 1 and 10 characters in length, inclusive, and only contain uppercase and lowercase letters.

Subtask 1 [10%]

M=2

MN100

All di will be in increasing order.

Subtask 2 [20%]

2M10

MN100000

Subtask 3 [70%]

2M10000

MN100000

Input Specification

The first line contains two space-separated integers, M and N.

The next M lines contain di and wi separated by a space.

Output Specification

Print the required sequence of words and numbers, with one item on each line.

Sample Input 1

Copy
2 10
2 Fizz
3 Coke

Sample Output 1

Copy
1
Fizz
Coke
Fizz
5
FizzCoke
7
Fizz
Coke
Fizz

Sample Input 2

Copy
3 7
2 Fizz
6 Pepsi
3 Coke

Sample Output 2

Copy
1
Fizz
Coke
Fizz
5
FizzCokePepsi
7

Comments

There are no comments at the moment.